5 // Created by Yifeng Huang on 7/26/12.
6 // Copyright (c) 2012 __MyCompanyName__. All rights reserved.
9 #import "TargetMouseMove.h"
11 #import "JoystickController.h"
13 @implementation TargetMouseMove
15 -(BOOL) isContinuous {
21 + (NSString *)serializationCode {
25 - (NSDictionary *)serialize {
26 return @{ @"type": @"mmove", @"dir": @(self.dir) };
29 + (Target *)targetDeserialize:(NSDictionary *)serialization
30 withConfigs:(NSArray *)configs {
31 TargetMouseMove *target = [[TargetMouseMove alloc] init];
32 target.dir = [serialization[@"dir"] intValue];
36 - (BOOL)update:(JoystickController *)jc {
37 //printf("Dir %d inputValue %f\n", [self dir], [self inputValue]);
38 if (fabs(self.magnitude) < 0.01)
39 return NO; // dead zone
41 NSRect screenRect = [[NSScreen mainScreen] frame];
42 NSInteger height = screenRect.size.height;
46 if ([jc frontWindowOnly])
48 float dx = 0.0, dy = 0.0;
50 dx = self.magnitude * speed;
52 dy = self.magnitude * speed;
53 NSPoint mouseLoc = jc.mouseLoc;
56 jc.mouseLoc = mouseLoc;
58 CGEventRef move = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved,
59 CGPointMake(mouseLoc.x, height - mouseLoc.y),
61 CGEventSetType(move, kCGEventMouseMoved);
62 CGEventSetIntegerValueField(move, kCGMouseEventDeltaX, dx);
63 CGEventSetIntegerValueField(move, kCGMouseEventDeltaY, dy);
65 if ([jc frontWindowOnly]) {
66 ProcessSerialNumber psn;
67 GetFrontProcess(&psn);
68 CGEventPostToPSN(&psn, move);
71 CGEventPost(kCGHIDEventTap, move);