5 // Created by Yifeng Huang on 7/26/12.
8 #import "TargetMouseMove.h"
10 #import "JoystickController.h"
12 @implementation TargetMouseMove {
16 -(BOOL) isContinuous {
20 + (NSString *)serializationCode {
24 - (NSDictionary *)serialize {
25 return @{ @"type": @"mmove", @"axis": @(_axis) };
28 + (Target *)targetDeserialize:(NSDictionary *)serialization
29 withConfigs:(NSArray *)configs {
30 TargetMouseMove *target = [[TargetMouseMove alloc] init];
31 target.axis = [serialization[@"axis"] intValue];
35 - (BOOL)update:(JoystickController *)jc {
36 if (fabsf(self.magnitude) < 0.01) {
38 return NO; // dead zone
41 // If the action crossed over High/Low, this target 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);