5 // Created by Yifeng Huang on 7/26/12.
8 #import "NJOutputMouseMove.h"
10 #import "NJDeviceController.h"
12 @implementation NJOutputMouseMove {
16 -(BOOL) isContinuous {
20 + (NSString *)serializationCode {
24 - (NSDictionary *)serialize {
25 return @{ @"type": @"mouse move", @"axis": @(_axis) };
28 + (NJOutput *)outputDeserialize:(NSDictionary *)serialization
29 withMappings:(NSArray *)mappings {
30 NJOutputMouseMove *output = [[NJOutputMouseMove alloc] init];
31 output.axis = [serialization[@"axis"] intValue];
35 - (BOOL)update:(NJDeviceController *)jc {
36 if (fabsf(self.magnitude) < 0.01) {
38 return NO; // dead zone
41 // If the input crossed over High/Low, this output is done.
43 sign = self.magnitude < 0 ? -1 : 1;
44 else if (sign / self.magnitude < 0) {
49 CGFloat height = NSScreen.mainScreen.frame.size.height;
53 if (jc.frontWindowOnly)
55 float dx = 0.f, dy = 0.f;
57 dx = self.magnitude * speed;
59 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);