Skip to content

Commit

Permalink
Change CGPostMouseEvent to CGEventCreateMouseEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
taromati committed Jul 12, 2016
1 parent 68ac877 commit dba971d
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions autoClicker.m 100644 → 100755
@@ -1,20 +1,28 @@
#import <Foundation/Foundation.h>
#import <ApplicationServices/ApplicationServices.h>

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;
void postMouseEvent(CGMouseButton button, CGEventType type, const CGPoint point) {
CGEventRef theEvent = CGEventCreateMouseEvent(NULL, type, point, button);
CGEventSetType(theEvent, type);
CGEventPost(kCGHIDEventTap, theEvent);
CFRelease(theEvent);
}

CGPostMouseEvent( pt, 1, 1, 1 );
CGPostMouseEvent( pt, 1, 1, 0 );

[pool release];
int main(int argc, char *argv[]) {
@autoreleasepool {
NSUserDefaults *args = [NSUserDefaults standardUserDefaults];

int x = [args integerForKey:@"x"];
int y = [args integerForKey:@"y"];

CGPoint pt;
pt.x = x;
pt.y = y;

postMouseEvent(kCGMouseButtonLeft, kCGEventLeftMouseDown, CGPointMake(x, y));
usleep(100 * 1000);
postMouseEvent(kCGMouseButtonLeft, kCGEventLeftMouseUp, CGPointMake(x, y));
}

return 0;
}
}

0 comments on commit dba971d

Please sign in to comment.