I am trying to simulate mouse move and mouse click on Mac using C or C++.
But unfortunately I don't find any Libraries for the same.
I have seen windows.h (works only for Windows) and also swinput (works for linux)
Is there anything like that for Mac?
2 Answers 2
CGPostMouseEvent has been deprecated in SnowLeopard. You can replace it with something like
CGEventRef mouseDownEv = CGEventCreateMouseEvent (NULL,kCGEventLeftMouseDown,pt,kCGMouseButtonLeft);
CGEventPost (kCGHIDEventTap, mouseDownEv);
CGEventRef mouseUpEv = CGEventCreateMouseEvent (NULL,kCGEventLeftMouseUp,pt,kCGMouseButtonLeft);
CGEventPost (kCGHIDEventTap, mouseUpEv );
CGEventRef CGEventCreateMouseEvent(
CGEventSourceRef source, // The event source may be taken from another event, or may be NULL.
CGEventType mouseType, // `mouseType' should be one of the mouse event types.
CGPoint mouseCursorPosition, // `mouseCursorPosition' should be the position of the mouse cursor in global coordinates.
CGMouseButton mouseButton); // `mouseButton' should be the button that's changing state;
// `mouseButton' is ignored unless `mouseType' is one of
// `kCGEventOtherMouseDown', `kCGEventOtherMouseDragged', or `kCGEventOtherMouseUp'.
Mouse button 0 is the primary button on the mouse. Mouse button 1 is the secondary mouse button (right). Mouse button 2 is the center button, and the remaining buttons are in USB device order.
kCGEventLeftMouseDown
kCGEventLeftMouseUp
kCGEventRightMouseDown
kCGEventRightMouseUp
kCGEventMouseMoved
kCGEventLeftMouseDragged
kCGEventRightMouseDragged
are now at your disposal.
Comments
My recommendation is that you check how the Mac ports of VNC do it.