forked from kendalpercimoney/enjoy2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTargetKeyboard.m
36 lines (29 loc) · 852 Bytes
/
TargetKeyboard.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
//
// TargetKeyboard.m
// Enjoy
//
// Created by Sam McCall on 5/05/09.
//
@implementation TargetKeyboard
@synthesize vk, descr;
-(NSString*) stringify {
return [[NSString alloc] initWithFormat: @"key~%d~%@", vk, descr];
}
+(TargetKeyboard*) unstringifyImpl: (NSArray*) comps {
NSParameterAssert([comps count] == 3);
TargetKeyboard* target = [[TargetKeyboard alloc] init];
[target setVk: [[comps objectAtIndex:1] integerValue]];
[target setDescr: [comps objectAtIndex:2]];
return target;
}
-(void) trigger: (JoystickController *)jc {
CGEventRef keyDown = CGEventCreateKeyboardEvent(NULL, vk, true);
CGEventPost(kCGHIDEventTap, keyDown);
CFRelease(keyDown);
}
-(void) untrigger: (JoystickController *)jc {
CGEventRef keyUp = CGEventCreateKeyboardEvent(NULL, vk, false);
CGEventPost(kCGHIDEventTap, keyUp);
CFRelease(keyUp);
}
@end