-
-
Save okkann/0b72fd71cb5f3bc95fa60a3c07d69fcf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env xcrun swift | |
import Foundation | |
let kDelayUSec : useconds_t = 500_000 | |
func DragMouse(from p0: CGPoint, to p1: CGPoint) { | |
let mouseDown = CGEventCreateMouseEvent(nil, .LeftMouseDown, p0, .Left) | |
let mouseDrag = CGEventCreateMouseEvent(nil, .LeftMouseDragged, p1, .Left) | |
let mouseUp = CGEventCreateMouseEvent(nil, .LeftMouseUp, p1, .Left) | |
CGEventPost(.CGHIDEventTap, mouseDown) | |
usleep(kDelayUSec) | |
CGEventPost(.CGHIDEventTap, mouseDrag) | |
usleep(kDelayUSec) | |
CGEventPost(.CGHIDEventTap, mouseUp) | |
} | |
func main() { | |
let args = NSUserDefaults.standardUserDefaults() | |
let x = CGFloat(args.integerForKey("x")) | |
let y = CGFloat(args.integerForKey("y")) | |
let dx = CGFloat(args.integerForKey("dx")) | |
let dy = CGFloat(args.integerForKey("dy")) | |
let p0 = CGPointMake(x, y) | |
let p1 = CGPointMake(x + dx, y + dy) | |
DragMouse(from: p0, to: p1) | |
} | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment