Search code examples
objective-cmacoscocoamouse-cursor

Set the mouse location


I need to be able to set the mouse location to the middle of the screen/window. How can I do that?


Solution

  • 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.