dd726e526bfa80aeb0a434dd3894b081809dc8b3
[enjoyable.git] / TargetMouseMove.m
1 //
2 // TargetMouseMove.m
3 // Enjoy
4 //
5 // Created by Yifeng Huang on 7/26/12.
6 // Copyright (c) 2012 __MyCompanyName__. All rights reserved.
7 //
8
9 #import "TargetMouseMove.h"
10
11 @implementation TargetMouseMove
12
13 -(void) setInputValue: (int) newIV {
14 NSPoint mouseLoc = [NSEvent mouseLocation];
15 if (dir == 0)
16 mouseLoc.x += newIV;
17 else
18 mouseLoc.y += newIV;
19
20 CGEventRef move = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved, CGPointMake(mouseLoc.x, mouseLoc.y), kCGMouseButtonLeft);
21 CGEventPost(kCGHIDEventTap, move);
22 CFRelease(move);
23 }
24
25 @synthesize dir;
26
27 -(NSString*) stringify {
28 return [[NSString alloc] initWithFormat: @"mmove~%d", dir];
29 }
30
31 +(TargetMouseMove*) unstringifyImpl: (NSArray*) comps {
32 NSParameterAssert([comps count] == 2);
33 TargetMouseMove* target = [[TargetMouseMove alloc] init];
34 [target setDir: [[comps objectAtIndex:1] integerValue]];
35 return target;
36 }
37
38 -(void) trigger {
39 return;
40 }
41
42 -(void) untrigger {
43 return;
44 }
45
46 @end