Permalink
Please sign in to comment.
38
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