Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 60 lines (45 sloc) 1.776 kb
ab71653 Justin Williams Initial Repository Import
justin authored
1 //
2 // SGKeyCodeTranslator.m
3 // SGHotKeyCenter
4 //
5 // Created by Justin Williams on 7/26/09.
6 // Copyright 2009 Second Gear. All rights reserved.
7 //
8
9 #import "SGKeyCodeTranslator.h"
10
11
12 @implementation SGKeyCodeTranslator
13
14 @synthesize keyboardLayout;
15
16 + (id)currentTranslator {
17 static SGKeyCodeTranslator *currentTranslator = nil;
18 TISInputSourceRef currentKeyboardLayout = TISCopyCurrentKeyboardInputSource();
19
45192c2 Justin Williams Added support for traditioanl retain/release memory management
justin authored
20 if (currentTranslator == nil) {
21 currentTranslator = [[SGKeyCodeTranslator alloc] initWithKeyboardLayout:currentKeyboardLayout];
22 } else if ([currentTranslator keyboardLayout] != currentKeyboardLayout) {
23 [currentTranslator release];
ab71653 Justin Williams Initial Repository Import
justin authored
24 currentTranslator = [[SGKeyCodeTranslator alloc] initWithKeyboardLayout:currentKeyboardLayout];
25 }
26
27 return currentTranslator;
28 }
29
30 - (id)initWithKeyboardLayout:(TISInputSourceRef)theLayout {
31 if ((self = [super init]) != nil) {
32 keyboardLayout = theLayout;
33 CFDataRef uchr = TISGetInputSourceProperty(keyboardLayout, kTISPropertyUnicodeKeyLayoutData);
34 keyboardLayoutData = (const UCKeyboardLayout *)CFDataGetBytePtr(uchr);
35 }
36
37 return self;
38 }
39
40
41 - (NSString *)translateKeyCode:(short)keyCode {
42 UniCharCount maxStringLength = 4, actualStringLength;
43 UniChar unicodeString[4];
44
45 UCKeyTranslate(keyboardLayoutData,
46 keyCode,
47 kUCKeyActionDisplay,
48 0,
49 LMGetKbdType(),
50 kUCKeyTranslateNoDeadKeysBit,
51 &deadKeyState,
52 maxStringLength,
53 &actualStringLength,
54 unicodeString);
55
56 return [NSString stringWithCharacters:unicodeString length:1];
57 }
58
59 @end
Something went wrong with that request. Please try again.