-
Notifications
You must be signed in to change notification settings - Fork 55
/
TargetMouseMove.m
78 lines (63 loc) · 1.91 KB
/
TargetMouseMove.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//
// TargetMouseMove.m
// Enjoy
//
// Created by Yifeng Huang on 7/26/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "TargetMouseMove.h"
@implementation TargetMouseMove
-(BOOL) isContinuous {
return true;
}
@synthesize dir;
-(NSString*) stringify {
return [[NSString alloc] initWithFormat: @"mmove~%d", dir];
}
+(TargetMouseMove*) unstringifyImpl: (NSArray*) comps {
NSParameterAssert([comps count] == 2);
TargetMouseMove* target = [[TargetMouseMove alloc] init];
[target setDir: [[comps objectAtIndex:1] integerValue]];
return target;
}
-(void) trigger: (JoystickController *)jc {
return;
}
-(void) untrigger: (JoystickController *)jc {
return;
}
-(void) update: (JoystickController *)jc {
//printf("Dir %d inputValue %f\n", [self dir], [self inputValue]);
if (fabs([self inputValue]) < 0.01)
return; // dead zone
NSRect screenRect = [[NSScreen mainScreen] frame];
NSInteger height = screenRect.size.height;
// TODO
double speed = 4.0;
if ([jc frontWindowOnly])
speed = 12.0;
double dx = 0.0, dy = 0.0;
if ([self dir] == 0)
dx = [self inputValue] * speed;
else
dy = [self inputValue] * speed;
NSPoint *mouseLoc = &jc->mouseLoc;
mouseLoc->x += dx;
mouseLoc->y -= dy;
CGEventRef move = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved,
CGPointMake(mouseLoc->x, height - mouseLoc->y),
0);
CGEventSetType(move, kCGEventMouseMoved);
CGEventSetIntegerValueField(move, kCGMouseEventDeltaX, dx);
CGEventSetIntegerValueField(move, kCGMouseEventDeltaY, dy);
if ([jc frontWindowOnly]) {
ProcessSerialNumber psn;
GetFrontProcess(&psn);
CGEventPostToPSN(&psn, move);
}
else {
CGEventPost(kCGHIDEventTap, move);
}
CFRelease(move);
}
@end