Created
June 21, 2017 19:26
-
-
Save orlv/cb3ac0f536a63b3bca41bf8e0f384cd6 to your computer and use it in GitHub Desktop.
Revisions
-
orlv created this gist
Jun 21, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,51 @@ // File: // click.m // // Compile with: // gcc -o click click.m -framework ApplicationServices -framework Foundation // // Usage: // ./click -x pixels -y pixels // At the given coordinates it will click and release. #import <Foundation/Foundation.h> #import <ApplicationServices/ApplicationServices.h> int main(int argc, char *argv[]) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSUserDefaults *args = [NSUserDefaults standardUserDefaults]; // grabs command line arguments -x and -y // int x = [args integerForKey:@"x"]; int y = [args integerForKey:@"y"]; // The data structure CGPoint represents a point in a two-dimensional // coordinate system. Here, X and Y distance from upper left, in pixels. // CGPoint pt; pt.x = x; pt.y = y; // This is where the magic happens. See CGRemoteOperation.h for details. // // CGPostMouseEvent( CGPoint mouseCursorPosition, // boolean_t updateMouseCursorPosition, // CGButtonCount buttonCount, // boolean_t mouseButtonDown, ... ) // // So, we feed coordinates to CGPostMouseEvent, put the mouse there, // then click and release. // CGPostMouseEvent( pt, 1, 1, 1 ); CGPostMouseEvent( pt, 1, 1, 0 ); [pool release]; return 0; }