I am utilizing NSEvent.mouseEvent()
to click on particular coordinates in one other app’s window, however after I change show decision/scaling, the identical coordinates (500, 300) click on totally different spots within the window.
func sendNSEventClick(at level: NSPoint, pid: pid_t, windowNumber: Int) {
guard let mouseDown = NSEvent.mouseEvent(
with: .leftMouseDown,
location: level,
modifierFlags: [],
timestamp: ProcessInfo.processInfo.systemUptime,
windowNumber: windowNumber,
context: nil,
eventNumber: 0,
clickCount: 1,
strain: 1.0
) else { return }
mouseDown.cgEvent?.postToPid(pid)
// ... mouseUp related
}
Easy check that fails:
// This could click on window middle, however clicks totally different spots at totally different resolutions
let centerPoint = NSPoint(x: windowFrame.width/2, y: windowFrame.peak/2)
sendNSEventClick(at: centerPoint, pid: pid, windowNumber: windowNumber)
How do I make coordinates decision/scaling impartial? Do I would like to use some scaling issue to the coordinates earlier than passing to NSEvent.mouseEvent()
?