so I need to be able to move the mouse to any given point (x and y). I'm trying to do it with CGDisplayMoveCursor while it moves the cursors it does not place it where I expect it. I have two monitors in my set up. I get the frame via NSScreen.screens[i].frame and these are their frames.
Built-in Retina Display
NSRect (0.0, 0.0, 1440.0, 900.0)
SwitchResX4 - LG HDR WQHD
NSRect (-1186.0, 900.0, 3840.0, 1600.0)
Then when I receive the new point I use NSRect.contains(NSPoint)
to find which of the two monitors contain that point. That part works as expected.
But then I want to move the cursor to that point but it doesn't work as you would expect (the cursor moves but not to the points as you would expect based on the frames). Here is the code for that.
let point = NSPoint(x: x, y: y)
guard let monitor = Monitor.displayIdWithPoint(point) else {
SendlogCallbackEvent("D", "", "Found nil in monitor with point", #function, #file, #line)
}
if CGDisplayMoveCursorToPoint(monitor.directDisplayId, point) == CGError.failure {
SendlogCallbackEvent("D", "", "CGError.failer to move cursor", #function, #file, #line)
}
I have read that it probably has to do with how CG and NS handle coordinate system in a different way but I haven't been able to figure how to make it work. How do I "convert" my NSPoint to a CGPoint so it works with CGDisplayMove... function. Or what is the best way to do this.