Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 73 lines (54 sloc) 1.902 kb
f1ecb587 »
2009-09-03 new version of quick cursor
1 //
2 // PTKeyCodeTranslator.m
3 // Chercher
4 //
5 // Created by Finlay Dobbie on Sat Oct 11 2003.
6 // Copyright (c) 2003 Cliché Software. All rights reserved.
7 //
8
9 #import "PTKeyCodeTranslator.h"
10
11
12 @implementation PTKeyCodeTranslator
13
14 + (id)currentTranslator
15 {
16 static PTKeyCodeTranslator *current = nil;
17 TISInputSourceRef currentLayout = TISCopyCurrentKeyboardLayoutInputSource();
18
19 if (current == nil) {
20 current = [[PTKeyCodeTranslator alloc] initWithKeyboardLayout:currentLayout];
21 } else if ([current keyboardLayout] != currentLayout) {
22 [current release];
23 current = [[PTKeyCodeTranslator alloc] initWithKeyboardLayout:currentLayout];
24 }
25
26 CFRelease(currentLayout);
27
28 return current;
29 }
30
31 - (id)initWithKeyboardLayout:(TISInputSourceRef)aLayout
32 {
33 if ((self = [super init]) != nil) {
34 keyboardLayout = aLayout;
35
36 CFRetain(keyboardLayout);
37
38 CFDataRef uchr = TISGetInputSourceProperty( keyboardLayout , kTISPropertyUnicodeKeyLayoutData );
39 uchrData = ( const UCKeyboardLayout* )CFDataGetBytePtr(uchr);
40 }
41
42 return self;
43 }
44
45 - (void)dealloc
46 {
47 CFRelease(keyboardLayout);
48
49 [super dealloc];
50 }
51
52 - (NSString *)translateKeyCode:(short)keyCode {
53 UniCharCount maxStringLength = 4, actualStringLength;
54 UniChar unicodeString[4];
55 UCKeyTranslate( uchrData, keyCode, kUCKeyActionDisplay, 0, LMGetKbdType(), kUCKeyTranslateNoDeadKeysBit, &deadKeyState, maxStringLength, &actualStringLength, unicodeString );
56 return [NSString stringWithCharacters:unicodeString length:1];
57 }
58
59 - (TISInputSourceRef)keyboardLayout {
60 return keyboardLayout;
61 }
62
63 - (NSString *)description {
64 NSString *kind;
65 kind = @"uchr";
66
67 NSString *layoutName;
68 layoutName = TISGetInputSourceProperty( keyboardLayout, kTISPropertyLocalizedName );
69 return [NSString stringWithFormat:@"PTKeyCodeTranslator layout=%@ (%@)", layoutName, kind];
70 }
71
72 @end
Something went wrong with that request. Please try again.