2 // NJOutputMouseScroll.m
5 // Created by Yifeng Huang on 7/28/12.
8 #import "NJOutputMouseScroll.h"
10 @implementation NJOutputMouseScroll {
14 + (NSString *)serializationCode {
15 return @"mouse scroll";
18 - (NSDictionary *)serialize {
19 return @{ @"type": @"mouse scroll", @"amount": @(_amount) };
22 + (NJOutput *)outputDeserialize:(NSDictionary *)serialization
23 withMappings:(NSArray *)mappings {
24 NJOutputMouseScroll *output = [[NJOutputMouseScroll alloc] init];
25 output.amount = [serialization[@"amount"] intValue];
30 if (!self.magnitude) {
31 CGEventRef scroll = CGEventCreateScrollWheelEvent(NULL,
32 kCGScrollEventUnitLine,
35 CGEventPost(kCGHIDEventTap, scroll);
40 - (BOOL)update:(NJDeviceController *)jc {
41 if (fabsf(self.magnitude) < 0.01f) {
43 return NO; // dead zone
46 // If the input crossed over High/Low, this output is done.
48 sign = self.magnitude < 0 ? -1 : 1;
49 else if (sign / self.magnitude < 0) {
54 int amount = (int)(16.f * fabsf(self.magnitude) * _amount);
55 CGEventRef scroll = CGEventCreateScrollWheelEvent(NULL,
56 kCGScrollEventUnitPixel,
59 CGEventPost(kCGHIDEventTap, scroll);
65 - (BOOL)isContinuous {