Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tag: 1.0
Fetching contributors…

Cannot retrieve contributors at this time

57 lines (42 sloc) 1.63 kb
//
// SGKeyCodeTranslator.m
// SGHotKeyCenter
//
// Created by Justin Williams on 7/26/09.
// Copyright 2009 Second Gear. All rights reserved.
//
#import "SGKeyCodeTranslator.h"
@implementation SGKeyCodeTranslator
@synthesize keyboardLayout;
+ (id)currentTranslator {
static SGKeyCodeTranslator *currentTranslator = nil;
TISInputSourceRef currentKeyboardLayout = TISCopyCurrentKeyboardInputSource();
if (currentTranslator == nil || [currentTranslator keyboardLayout] != currentKeyboardLayout) {
currentTranslator = [[SGKeyCodeTranslator alloc] initWithKeyboardLayout:currentKeyboardLayout];
}
return currentTranslator;
}
- (id)initWithKeyboardLayout:(TISInputSourceRef)theLayout {
if ((self = [super init]) != nil) {
keyboardLayout = theLayout;
CFDataRef uchr = TISGetInputSourceProperty(keyboardLayout, kTISPropertyUnicodeKeyLayoutData);
keyboardLayoutData = (const UCKeyboardLayout *)CFDataGetBytePtr(uchr);
}
return self;
}
- (NSString *)translateKeyCode:(short)keyCode {
UniCharCount maxStringLength = 4, actualStringLength;
UniChar unicodeString[4];
UCKeyTranslate(keyboardLayoutData,
keyCode,
kUCKeyActionDisplay,
0,
LMGetKbdType(),
kUCKeyTranslateNoDeadKeysBit,
&deadKeyState,
maxStringLength,
&actualStringLength,
unicodeString);
return [NSString stringWithCharacters:unicodeString length:1];
}
@end
Jump to Line
Something went wrong with that request. Please try again.