Created
September 28, 2015 11:00
-
-
Save sordina/91122c3a7d7ee20bbe30 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
#include <ApplicationServices/ApplicationServices.h> | |
#include <unistd.h> | |
int main() { | |
// Left button down | |
CGEventRef click1_down = CGEventCreateMouseEvent( | |
NULL, kCGEventLeftMouseDown, | |
CGPointMake(200, 200), | |
kCGMouseButtonLeft | |
); | |
// Move to 200x200 | |
CGEventRef move0 = CGEventCreateMouseEvent( | |
NULL, kCGEventMouseMoved, | |
CGPointMake(200, 200), | |
kCGMouseButtonLeft // ignored | |
); | |
// Move to 200x200 | |
CGEventRef move1 = CGEventCreateMouseEvent( | |
NULL, kCGEventMouseMoved, | |
CGPointMake(200, 200), | |
kCGMouseButtonLeft // ignored | |
); | |
// Move to 250x250 | |
CGEventRef move2 = CGEventCreateMouseEvent( | |
NULL, kCGEventLeftMouseDragged, | |
CGPointMake(250, 250), | |
kCGMouseButtonLeft // ignored | |
); | |
// Left button up at 250x250 | |
CGEventRef click1_up = CGEventCreateMouseEvent( | |
NULL, kCGEventLeftMouseUp, | |
CGPointMake(250, 250), | |
kCGMouseButtonLeft | |
); | |
// Now, execute these events with an interval to make them noticeable | |
CGEventPost(kCGHIDEventTap, move0); | |
CGEventPost(kCGHIDEventTap, click1_down); | |
sleep(1); | |
CGEventPost(kCGHIDEventTap, move1); | |
sleep(1); | |
CGEventPost(kCGHIDEventTap, move2); | |
sleep(1); | |
CGEventPost(kCGHIDEventTap, click1_up); | |
// Release the events | |
CFRelease(click1_up); | |
CFRelease(click1_down); | |
CFRelease(move2); | |
CFRelease(move1); | |
CFRelease(move0); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment