5

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?

BЈовић
64.7k45 gold badges181 silver badges284 bronze badges
asked Nov 7, 2011 at 2:59

2 Answers 2

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.

answered Feb 4, 2012 at 12:02
Sign up to request clarification or add additional context in comments.

Comments

1

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

answered Nov 7, 2011 at 3:05

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.