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 objectAtIndex:1] integerValue]];
30 -(void) trigger: (JoystickController *)jc {
34 -(void) untrigger: (JoystickController *)jc {
38 -(void) update: (JoystickController *)jc {
39 //printf("Dir %d inputValue %f\n", [self dir], [self inputValue]);
40 if (fabs([self inputValue]) < 0.01)
43 NSRect screenRect = [[NSScreen mainScreen] frame];
44 NSInteger height = screenRect.size.height;
48 if ([jc frontWindowOnly])
50 double dx = 0.0, dy = 0.0;
52 dx = [self inputValue] * speed;
54 dy = [self inputValue] * speed;
55 NSPoint *mouseLoc = &jc->mouseLoc;
59 CGEventRef move = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved,
60 CGPointMake(mouseLoc->x, height - mouseLoc->y),
62 CGEventSetType(move, kCGEventMouseMoved);
63 CGEventSetIntegerValueField(move, kCGMouseEventDeltaX, dx);
64 CGEventSetIntegerValueField(move, kCGMouseEventDeltaY, dy);
66 if ([jc frontWindowOnly]) {
67 ProcessSerialNumber psn;
68 GetFrontProcess(&psn);
69 CGEventPostToPSN(&psn, move);
72 CGEventPost(kCGHIDEventTap, move);