I am looking for a way to retrieve the cursor position to later set the position back with CGDisplayMoveCursorToPoint. I can’t find any function like CGDisplayGetCursorPosition in Quartz Display References.
Does anybody know how to retrieve the (absolute) position of the cursor in Mac OS X?
Use one of the answers at Cocoa: Getting the current mouse position on the screen to get the mouse position in global coordinates.
To call
CGDisplayMoveCursorToPoint, get the display containing that position usingCGGetDisplaysWithPoint, and then use the rect returned byCGDisplayBoundsto convert the global point to a screen-local point.Or just use
CGWarpMouseCursorPositioninstead ofCGDisplayMoveCursorToPoint, sinceCGWarpMouseCursorPositionjust takes a global point and no display.