Set mouse location

I need to set the location of the mouse in the middle of the screen / window. How can i do this?

+7
source share
3 answers

The documentation seems to indicate that CGDisplayMoveCursorToPoint or CGWarpMouseCursorPosition will do what you need.

EDIT: to match your last comment, I would recommend CGWarpMouseCursorPosition , which is mentioned in the docs:

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 fixed by the edges of the display.

+9
source

I worked on what happened 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> 
+4
source

You can use [NSEvent mouseLocation] to get the current cursor location, but I could not find any way to directly set the position to the center of the screen.

-one
source

All Articles