Automatically trigger/untrigger targets based on setting the 'running' property;...
[enjoyable.git] / TargetMouseScroll.m
1 //
2 // TargetMouseScroll.m
3 // Enjoy
4 //
5 // Created by Yifeng Huang on 7/28/12.
6 // Copyright (c) 2012 __MyCompanyName__. All rights reserved.
7 //
8
9 #import "TargetMouseScroll.h"
10
11 @implementation TargetMouseScroll
12
13 @synthesize howMuch;
14
15 -(NSString*) stringify {
16 return [[NSString alloc] initWithFormat: @"mscroll~%d", howMuch];
17 }
18
19 +(TargetMouseScroll*) unstringifyImpl: (NSArray*) comps {
20 NSParameterAssert([comps count] == 2);
21 TargetMouseScroll* target = [[TargetMouseScroll alloc] init];
22 [target setHowMuch: [comps[1] integerValue]];
23 return target;
24 }
25
26 -(void) trigger {
27 CGEventRef scroll = CGEventCreateScrollWheelEvent(NULL,
28 kCGScrollEventUnitLine,
29 1,
30 [self howMuch]);
31 CGEventPost(kCGHIDEventTap, scroll);
32 CFRelease(scroll);
33 }
34
35 @end