2bcbce378a194557116cdb6e9618a81fb4fe9f50
[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 NSRect screenRect = [[NSScreen mainScreen] frame];
15 NSInteger height = screenRect.size.height;
16 NSPoint mouseLoc = [NSEvent mouseLocation];
17 if (dir == 0)
18 mouseLoc.x += newIV;
19 else
20 mouseLoc.y += newIV;
21
22 CGEventRef move = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved,
23 CGPointMake(mouseLoc.x, height - mouseLoc.y),
24 kCGMouseButtonLeft);
25 CGEventPost(kCGHIDEventTap, move);
26 CFRelease(move);
27 }
28
29 @synthesize dir;
30
31 -(NSString*) stringify {
32 return [[NSString alloc] initWithFormat: @"mmove~%d", dir];
33 }
34
35 +(TargetMouseMove*) unstringifyImpl: (NSArray*) comps {
36 NSParameterAssert([comps count] == 2);
37 TargetMouseMove* target = [[TargetMouseMove alloc] init];
38 [target setDir: [[comps objectAtIndex:1] integerValue]];
39 return target;
40 }
41
42 -(void) trigger {
43 return;
44 }
45
46 -(void) untrigger {
47 return;
48 }
49
50 @end