Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change CGPostMouseEvent to CGEventCreateMouseEvent
- Loading branch information
taromati
committed
Jul 12, 2016
1 parent
68ac877
commit dba971d
Showing
1 changed file
with
23 additions
and
15 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |