I need to be able to set the mouse location to the middle of the screen/window. How can I do that?
The documentation seems to indicate that CGDisplayMoveCursorToPoint or CGWarpMouseCursorPosition will do what you're after.
EDIT: To match your latest comment, I would further recommend CGWarpMouseCursorPosition
, about which the docs state:
For example, this function is often used to move the cursor position back to the center of the screen by games that do not want the cursor pinned by display edges.
I was working on something like that last week.
CGEventSourceRef source = CGEventSourceCreate(kCGEventSourceStateCombinedSessionState);
CGEventRef mouse = CGEventCreateMouseEvent (NULL, kCGEventMouseMoved, CGPointMake( X, Y), 0);
CGEventPost(kCGHIDEventTap, mouse);
CFRelease(mouse);
CFRelease(source);
Just set X and Y.
EDIT:
#include <ApplicationServices/ApplicationServices.h>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With