Last active
June 21, 2016 11:22
-
-
Save infusion/a2874accee64d17f92a3 to your computer and use it in GitHub Desktop.
Simulate clicks on OSX with C
This file contains 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
// gcc -o click click.c -Wall -framework ApplicationServices | |
#include <ApplicationServices/ApplicationServices.h> | |
#include <unistd.h> | |
// Coord to click on | |
#define X 422 | |
#define Y 192 | |
int main() { | |
// Create MouseDown event | |
CGEventRef click1_down = CGEventCreateMouseEvent( | |
NULL, kCGEventLeftMouseDown, | |
CGPointMake(X, Y), | |
kCGMouseButtonLeft | |
); | |
// Create MouseUp event | |
CGEventRef click1_up = CGEventCreateMouseEvent( | |
NULL, kCGEventLeftMouseUp, | |
CGPointMake(X, Y), | |
kCGMouseButtonLeft | |
); | |
// Click 100x | |
for (int i = 0; i < 100; i++) { | |
// Mouse down | |
CGEventPost(kCGHIDEventTap, click1_down); | |
sleep(1); | |
// Mouse up | |
CGEventPost(kCGHIDEventTap, click1_up); | |
sleep(1); | |
} | |
// Release the events | |
CFRelease(click1_up); | |
CFRelease(click1_down); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment