How can I set the mouse position?

core-graphics, macos, macos-carbon

Solution

The real answer to this question is:

CGMainDisplayID()

https://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/Quartz_Services_Ref/index.html#//apple_ref/c/func/CGMainDisplayID

CGDisplayMoveCursorToPoint(CGMainDisplayID(), point);

Problem

I need to set the position of the mouse on the screen. In some other similar question, it was suggested to use `CGDisplayMoveCursorToPoint(CGDirectDisplayID display, CGPoint point)`, but I cannot figure out how to get the `CGDirectDisplayID`. Please tell me how to get the `CGDirectDisplayID` or a different method to set the mouse position.

Original source