5 // Created by Yifeng Huang on 7/26/12.
6 // Copyright (c) 2012 __MyCompanyName__. All rights reserved.
9 #import "TargetMouseMove.h"
11 @implementation TargetMouseMove
13 -(BOOL) isContinuous {
19 -(NSString*) stringify {
20 return [[NSString alloc] initWithFormat: @"mmove~%d", dir];
23 +(TargetMouseMove*) unstringifyImpl: (NSArray*) comps {
24 NSParameterAssert([comps count] == 2);
25 TargetMouseMove* target = [[TargetMouseMove alloc] init];
26 [target setDir: [comps[1] integerValue]];
30 - (BOOL)update:(JoystickController *)jc {
31 //printf("Dir %d inputValue %f\n", [self dir], [self inputValue]);
32 if (fabs(self.magnitude) < 0.01)
33 return NO; // dead zone
35 NSRect screenRect = [[NSScreen mainScreen] frame];
36 NSInteger height = screenRect.size.height;
40 if ([jc frontWindowOnly])
42 float dx = 0.0, dy = 0.0;
44 dx = self.magnitude * speed;
46 dy = self.magnitude * speed;
47 NSPoint mouseLoc = jc.mouseLoc;
50 jc.mouseLoc = mouseLoc;
52 CGEventRef move = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved,
53 CGPointMake(mouseLoc.x, height - mouseLoc.y),
55 CGEventSetType(move, kCGEventMouseMoved);
56 CGEventSetIntegerValueField(move, kCGMouseEventDeltaX, dx);
57 CGEventSetIntegerValueField(move, kCGMouseEventDeltaY, dy);
59 if ([jc frontWindowOnly]) {
60 ProcessSerialNumber psn;
61 GetFrontProcess(&psn);
62 CGEventPostToPSN(&psn, move);
65 CGEventPost(kCGHIDEventTap, move);