Skip to content

Instantly share code, notes, and snippets.

@dsturnbull
Created February 9, 2010 04:56
Show Gist options
  • Save dsturnbull/298926 to your computer and use it in GitHub Desktop.
Save dsturnbull/298926 to your computer and use it in GitHub Desktop.
#import <Foundation/Foundation.h>
#import <ApplicationServices/ApplicationServices.h>
void move_mouse(const CGPoint pt);
int main(int argc, char *argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSUserDefaults *args = [NSUserDefaults standardUserDefaults];
int x = [args integerForKey:@"x"];
int y = [args integerForKey:@"y"];
CGPoint pt;
pt.x = x;
pt.y = y;
move_mouse(pt);
pt.x += 10;
move_mouse(pt);
[pool release];
return 0;
}
void move_mouse(const CGPoint pt) {
CGEventRef theEvent = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved, pt, kCGMouseButtonLeft);
CGEventSetType(theEvent, kCGEventMouseMoved);
CGEventPost(kCGHIDEventTap, theEvent);
CFRelease(theEvent);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment