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 *)outputWithSerialization:(NSDictionary *)serialization {
25 NJOutputMouseScroll *output = [[NJOutputMouseScroll alloc] init];
26 output.direction = [serialization[@"direction"] intValue];
27 output.speed = [serialization[@"speed"] floatValue];
28 output.smooth = [serialization[@"smooth"] boolValue];
32 - (BOOL)isContinuous {
37 int amount = abs(_direction) == n ? _direction / n : 0;
39 amount *= _speed * self.magnitude;
45 CGEventRef scroll = CGEventCreateScrollWheelEvent(NULL,
46 kCGScrollEventUnitLine,
50 CGEventPost(kCGHIDEventTap, scroll);
55 - (BOOL)update:(NJInputController *)ic {
56 if (self.magnitude < 0.05f)
57 return NO; // dead zone
59 CGEventRef scroll = CGEventCreateScrollWheelEvent(NULL,
60 kCGScrollEventUnitPixel,
64 CGEventPost(kCGHIDEventTap, scroll);