2 // NJOutputMouseScroll.m
5 // Created by Yifeng Huang on 7/28/12.
8 #import "NJOutputMouseScroll.h"
10 @implementation NJOutputMouseScroll
12 + (NSString *)serializationCode {
13 return @"mouse scroll";
16 - (NSDictionary *)serialize {
17 return @{ @"type": self.class.serializationCode,
18 @"direction": @(_direction),
20 @"smooth": @(_smooth),
24 + (NJOutput *)outputDeserialize:(NSDictionary *)serialization
25 withMappings:(NSArray *)mappings {
26 NJOutputMouseScroll *output = [[NJOutputMouseScroll alloc] init];
27 output.direction = [serialization[@"direction"] intValue];
28 output.speed = [serialization[@"speed"] floatValue];
29 output.smooth = [serialization[@"smooth"] boolValue];
33 - (BOOL)isContinuous {
38 int amount = abs(_direction) == n ? _direction / n : 0;
40 amount *= _speed * self.magnitude;
46 CGEventRef scroll = CGEventCreateScrollWheelEvent(NULL,
47 kCGScrollEventUnitLine,
51 CGEventPost(kCGHIDEventTap, scroll);
56 - (BOOL)update:(NJDeviceController *)jc {
57 if (self.magnitude < 0.05f)
58 return NO; // dead zone
60 CGEventRef scroll = CGEventCreateScrollWheelEvent(NULL,
61 kCGScrollEventUnitPixel,
65 CGEventPost(kCGHIDEventTap, scroll);