Come adattamento dal codice @ mat-burns in questo post
(Nota Avrai anche bisogno di xcode installato.)
#!/usr/bin/env xcrun swift
import Foundation
let kDelayUSec : useconds_t = 500_000
func moveMouseClick( p1: CGPoint) {
let mouseMove = CGEventCreateMouseEvent(nil, CGEventType(kCGEventLeftMouseDragged), p1, CGMouseButton(kCGMouseButtonLeft)).takeUnretainedValue()
let mouseDown = CGEventCreateMouseEvent(nil, CGEventType(kCGEventLeftMouseDown), p1, CGMouseButton(kCGMouseButtonLeft)).takeUnretainedValue()
let mouseUp = CGEventCreateMouseEvent(nil, CGEventType(kCGEventLeftMouseUp), p1, CGMouseButton(kCGMouseButtonLeft)).takeUnretainedValue()
CGEventPost(CGEventTapLocation(kCGHIDEventTap), mouseMove)
usleep(kDelayUSec)
CGEventPost(CGEventTapLocation(kCGHIDEventTap), mouseDown)
usleep(kDelayUSec)
CGEventPost(CGEventTapLocation(kCGHIDEventTap), mouseUp)
}
func main() {
let pointX = 396
let pointY = 214
let p1 = CGPointMake( CGFloat(pointX), CGFloat(pointY))
moveMouseClick( p1)
}
main()
Cambia le linee:
let pointX = 396
let pointY = 214
per riflettere il punto di clic.
Salva questo codice come moveClick.swift
E poi in Terminal.app esegui /bin/chmod +x ~/scripts/moveClick.swift
per rendere eseguibile lo script
Cambia ~ / scripts / moveClick.swift nel percorso attuale del tuo file rapido.
Non ho maestro di tastiera Ma vedo che può eseguire uno script di shell.
Esegui un'azione script di shell
~/scripts/moveClick.swift
Nell'esempio sopra abbiamo codificato il punto di clic.
Ma se vuoi renderlo versatile, possiamo fare in modo che il codice prenda argomenti.
Usando questo codice, invece.
#!/usr/bin/env xcrun swift
import Foundation
let kDelayUSec : useconds_t = 500_000
func moveMouseClick( p1: CGPoint) {
let mouseMove = CGEventCreateMouseEvent(nil, CGEventType(kCGEventLeftMouseDragged), p1, CGMouseButton(kCGMouseButtonLeft)).takeUnretainedValue()
let mouseDown = CGEventCreateMouseEvent(nil, CGEventType(kCGEventLeftMouseDown), p1, CGMouseButton(kCGMouseButtonLeft)).takeUnretainedValue()
let mouseUp = CGEventCreateMouseEvent(nil, CGEventType(kCGEventLeftMouseUp), p1, CGMouseButton(kCGMouseButtonLeft)).takeUnretainedValue()
CGEventPost(CGEventTapLocation(kCGHIDEventTap), mouseMove)
usleep(kDelayUSec)
CGEventPost(CGEventTapLocation(kCGHIDEventTap), mouseDown)
usleep(kDelayUSec)
CGEventPost(CGEventTapLocation(kCGHIDEventTap), mouseUp)
}
func main() {
let p1 = CGPointMake( CGFloat(atof( C_ARGV[1])), CGFloat(atof( C_ARGV[2])))
moveMouseClick( p1)
}
main()
Again in Keyboard maestro.
Esegui un'azione script di shell
~/scripts/moveClick.swift 396, 214