5 // Created by Yifeng Huang on 7/26/12.
8 #import "NJOutputMouseMove.h"
10 #import "NJDeviceController.h"
12 @implementation NJOutputMouseMove
14 -(BOOL) isContinuous {
18 + (NSString *)serializationCode {
22 - (NSDictionary *)serialize {
23 return @{ @"type": self.class.serializationCode,
29 + (NJOutput *)outputDeserialize:(NSDictionary *)serialization
30 withMappings:(NSArray *)mappings {
31 NJOutputMouseMove *output = [[NJOutputMouseMove alloc] init];
32 output.axis = [serialization[@"axis"] intValue];
33 output.speed = [serialization[@"speed"] floatValue];
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);
72 if (jc.frontWindowOnly) {
73 ProcessSerialNumber psn;
74 GetFrontProcess(&psn);
75 CGEventPostToPSN(&psn, move);
78 CGEventPost(kCGHIDEventTap, move);