-
-
Save mgreiner/353aadf3dda008b1ca86 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(p0: CGPoint, p1: CGPoint) { | |
let mouseDown = CGEventCreateMouseEvent(nil, .LeftMouseDown, p0, CGMouseButton.Left) | |
let mouseDrag = CGEventCreateMouseEvent(nil, .LeftMouseDragged, p1, CGMouseButton.Left) | |
let mouseUp = CGEventCreateMouseEvent(nil, .LeftMouseUp, p1, CGMouseButton.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(p0, p1: p1) | |
} | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to use postToPid ???