How to simulate mouse move and mouse click on Mac using C or C++

一个人想着一个人 提交于 2019-12-04 12:57:21

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.

My recommendation is that you check how the Mac ports of VNC do it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!