Forked Enjoy, mouse movement
[enjoyable.git] / TargetMouseBtn.m
1 //
2 // TargetMouseBtn.m
3 // Enjoy
4 //
5 // Created by Yifeng Huang on 7/27/12.
6 // Copyright (c) 2012 __MyCompanyName__. All rights reserved.
7 //
8
9 #import "TargetMouseBtn.h"
10
11 @implementation TargetMouseBtn
12
13 @synthesize which;
14
15 -(NSString*) stringify {
16 return [[NSString alloc] initWithFormat: @"mbtn~%d", which];
17 }
18
19 +(TargetMouseBtn*) unstringifyImpl: (NSArray*) comps {
20 NSParameterAssert([comps count] == 2);
21 TargetMouseBtn* target = [[TargetMouseBtn alloc] init];
22 [target setWhich: [[comps objectAtIndex:1] integerValue]];
23 return target;
24 }
25
26 -(void) trigger {
27 NSPoint mouseLoc = [NSEvent mouseLocation];
28 CGEventType eventType = (which == kCGMouseButtonLeft) ? kCGEventLeftMouseDown : kCGEventRightMouseDown;
29 CGEventRef click = CGEventCreateMouseEvent(NULL,
30 eventType,
31 CGPointMake(mouseLoc.x, mouseLoc.y),
32 which);
33 CGEventPost(kCGHIDEventTap, click);
34 CFRelease(click);
35 }
36
37 -(void) untrigger {
38 NSPoint mouseLoc = [NSEvent mouseLocation];
39 CGEventType eventType = (which == kCGMouseButtonLeft) ? kCGEventLeftMouseUp : kCGEventRightMouseUp;
40 CGEventRef click = CGEventCreateMouseEvent(NULL,
41 eventType,
42 CGPointMake(mouseLoc.x, mouseLoc.y),
43 which);
44 CGEventPost(kCGHIDEventTap, click);
45 CFRelease(click);
46 }
47
48 @end