Код: Выделить всё
func sendNSEventClick(at point: NSPoint, pid: pid_t, windowNumber: Int) {
guard let mouseDown = NSEvent.mouseEvent(
with: .leftMouseDown,
location: point,
modifierFlags: [],
timestamp: ProcessInfo.processInfo.systemUptime,
windowNumber: windowNumber,
context: nil,
eventNumber: 0,
clickCount: 1,
pressure: 1.0
) else { return }
mouseDown.cgEvent?.postToPid(pid)
// ... mouseUp similar
}
Код: Выделить всё
// This should click window center, but clicks different spots at different resolutions
let centerPoint = NSPoint(x: windowFrame.width/2, y: windowFrame.height/2)
sendNSEventClick(at: centerPoint, pid: pid, windowNumber: windowNumber)
Подробнее здесь: https://stackoverflow.com/questions/797 ... ick-consis
Мобильная версия