4d6f409a97d2804765f74109447c2c3642837763
[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 amount;
14
15 + (NSString *)serializationCode {
16 return @"mscroll";
17 }
18
19 - (NSDictionary *)serialize {
20 return @{ @"type": @"mscroll", @"amount": @(self.amount) };
21 }
22
23 + (Target *)targetDeserialize:(NSDictionary *)serialization
24 withConfigs:(NSArray *)configs {
25 TargetMouseScroll *target = [[TargetMouseScroll alloc] init];
26 target.amount = [serialization[@"amount"] intValue];
27 return target;
28 }
29 -(void) trigger {
30 CGEventRef scroll = CGEventCreateScrollWheelEvent(NULL,
31 kCGScrollEventUnitLine,
32 1,
33 self.amount);
34 CGEventPost(kCGHIDEventTap, scroll);
35 CFRelease(scroll);
36 }
37
38 @end