Skip to content
Newer
Older
100644 79 lines (61 sloc) 2.07 KB
b39da64 initial commit
chendo authored
1 //
2 // Telefrag.m
3 // Telefrag
4 //
5 // Created by chendo on 17/08/09.
451b9ce cleaned up and refactored the code, added proper copyright notice to …
chendo authored
6 // Copyright 2009 chendo. All rights reserved.
b39da64 initial commit
chendo authored
7 //
8
9 #import "Telefrag.h"
7fbc878 holy crap this code is fugly but it works
chendo authored
10 #import "MethodSwizzle.h"
b39da64 initial commit
chendo authored
11
7fbc878 holy crap this code is fugly but it works
chendo authored
12 @implementation TPEventTapsController (Telefrag)
b39da64 initial commit
chendo authored
13
535f46a fixed bundle path
chendo authored
14 - (void) _sendEventToListener_s:(CGEventRef)event{
7fbc878 holy crap this code is fugly but it works
chendo authored
15 CGEventType type = CGEventGetType(event);
16
451b9ce cleaned up and refactored the code, added proper copyright notice to …
chendo authored
17 if (type == kCGEventKeyDown || type == kCGEventKeyUp) {
7fbc878 holy crap this code is fugly but it works
chendo authored
18 CGKeyCode keyCode = CGEventGetIntegerValueField( event, kCGKeyboardEventKeycode );
19
451b9ce cleaned up and refactored the code, added proper copyright notice to …
chendo authored
20 int charCode = (int)keyCode;
21 int mappedKeycode = [Telefrag getMappedKeycode:charCode];
22 if (mappedKeycode != -1) {
23 CGEventSetIntegerValueField(event, kCGKeyboardEventKeycode, mappedKeycode);
7fbc878 holy crap this code is fugly but it works
chendo authored
24 }
451b9ce cleaned up and refactored the code, added proper copyright notice to …
chendo authored
25
7fbc878 holy crap this code is fugly but it works
chendo authored
26 }
27 [self _sendEventToListener_s:event];
28 }
29
30 @end
31
32
33
34 @implementation Telefrag : NSObject
b39da64 initial commit
chendo authored
35
451b9ce cleaned up and refactored the code, added proper copyright notice to …
chendo authored
36 static NSDictionary *moddedKeymap;
37
b39da64 initial commit
chendo authored
38 + (void) load {
39 NSLog(@"telefrag loaded");
7fbc878 holy crap this code is fugly but it works
chendo authored
40
41 if (MethodSwizzle(NSClassFromString(@"TPEventTapsController"), @selector(_sendEventToListener:), @selector(_sendEventToListener_s:))) {
451b9ce cleaned up and refactored the code, added proper copyright notice to …
chendo authored
42 NSLog(@"telefrag swizzled TFEventTapsController");
7fbc878 holy crap this code is fugly but it works
chendo authored
43 }
44
451b9ce cleaned up and refactored the code, added proper copyright notice to …
chendo authored
45 }
46
47 + (int) getMappedKeycode:(int) keyCode {
48 if (moddedKeymap == NULL) {
49 [self loadKeymap];
50 }
51 NSString *key = [NSString stringWithFormat:@"%d", keyCode];
52 NSNumber *value;
53 if (value = (NSNumber *)[moddedKeymap objectForKey:key]) {
54 return [value integerValue];
7fbc878 holy crap this code is fugly but it works
chendo authored
55 }
451b9ce cleaned up and refactored the code, added proper copyright notice to …
chendo authored
56 else {
57 return -1;
58 }
59 }
60
61 + (void) loadKeymap {
62 NSString *errorDesc = nil;
63 NSPropertyListFormat format;
535f46a fixed bundle path
chendo authored
64 NSString *plistPath = [[NSBundle bundleForClass:self] pathForResource:@"Keymap" ofType:@"plist"];
abbb547 telefrag now supports colemak, dvorak and qwerty bidirectionally
Jack Chen authored
65 if (plistPath == NULL) {
66 NSLog(@"Keymap.plist not found; have you made the symlink yet?");
67 return;
68 }
451b9ce cleaned up and refactored the code, added proper copyright notice to …
chendo authored
69 NSData *plistXML = [[NSFileManager defaultManager] contentsAtPath:plistPath];
70 moddedKeymap = (NSDictionary *)[NSPropertyListSerialization
71 propertyListFromData:plistXML
72 mutabilityOption:NSPropertyListMutableContainersAndLeaves
73 format:&format errorDescription:&errorDesc];
a6b876c fixed the final bug, telefrag is complete
chendo authored
74 [moddedKeymap retain];
451b9ce cleaned up and refactored the code, added proper copyright notice to …
chendo authored
75 NSLog(@"keymap loaded: %@", moddedKeymap);
b39da64 initial commit
chendo authored
76 }
77
78 @end
Something went wrong with that request. Please try again.