问题
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?
回答1:
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.
回答2:
My recommendation is that you check how the Mac ports of VNC do it.
来源:https://stackoverflow.com/questions/8032322/how-to-simulate-mouse-move-and-mouse-click-on-mac-using-c-or-c