Hello. What API or framework to use to simulate a mouse click on an iPad connected as an external display?
An iPad connected to the Mac via USB in a mode "Linked keyboard and mouse".
What is the way to simulate a mouse click at a specific coordinate at such a display?
So far I tried to simulate a click with CGEvent like so
if
let eventDown = CGEvent(mouseEventSource: source, mouseType: .leftMouseDown, mouseCursorPosition: point, mouseButton: .left),
let eventUp = CGEvent(mouseEventSource: source, mouseType: .leftMouseUp, mouseCursorPosition: point, mouseButton: .left)
{
eventDown.post(tap: .cghidEventTap)
usleep(500_000)
eventUp.post(tap: .cghidEventTap)
}
but it seems it does not work even on the main display. I set the point to the coordinate outside of the app window so that on a click another app should be focused but it does not happen on a simulated click.
I also tried to find a way to get a mouse coordinate on the external screen with addLocalMonitorForEvents. If I listen for the event
NSEvent.addLocalMonitorForEvents(matching: [.mouseMoved]) { event in
debugPrint("NSEvent.mouseLocation:", NSEvent.mouseLocation)
return event
}
it only works when the cursor is on the main screen and stops reporting as soon as the mouse enters the iPad.
So, any advice is welcomed on which direction I should look.