5 // Created by Yifeng Huang on 7/26/12.
8 #import "NJOutputMouseMove.h"
10 #import "NJDeviceController.h"
12 @implementation NJOutputMouseMove
14 + (NSString *)serializationCode {
18 - (NSDictionary *)serialize {
19 return @{ @"type": self.class.serializationCode,
25 + (NJOutput *)outputDeserialize:(NSDictionary *)serialization
26 withMappings:(NSArray *)mappings {
27 NJOutputMouseMove *output = [[NJOutputMouseMove alloc] init];
28 output.axis = [serialization[@"axis"] intValue];
29 output.speed = [serialization[@"speed"] floatValue];
35 - (BOOL)isContinuous {
39 - (BOOL)update:(NJDeviceController *)jc {
40 if (self.magnitude < 0.05)
41 return NO; // dead zone
43 CGFloat height = NSScreen.mainScreen.frame.size.height;
45 float dx = 0.f, dy = 0.f;
48 dx = -self.magnitude * _speed;
51 dx = self.magnitude * _speed;
54 dy = -self.magnitude * _speed;
57 dy = self.magnitude * _speed;
60 NSPoint mouseLoc = jc.mouseLoc;
63 jc.mouseLoc = mouseLoc;
65 CGEventRef move = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved,
66 CGPointMake(mouseLoc.x, height - mouseLoc.y),
68 CGEventSetType(move, kCGEventMouseMoved);
69 CGEventSetIntegerValueField(move, kCGMouseEventDeltaX, (int)dx);
70 CGEventSetIntegerValueField(move, kCGMouseEventDeltaY, (int)dy);
71 CGEventPost(kCGHIDEventTap, move);