Skip to content

Instantly share code, notes, and snippets.

@curthard89
Created January 5, 2012 13:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save curthard89/1565244 to your computer and use it in GitHub Desktop.
Save curthard89/1565244 to your computer and use it in GitHub Desktop.
+ (UniChar)characterForVirtualKeyCode:(NSInteger)keyCode
{
/**************
THIS REQUIRES THE CARBON FRAMEWORK!
***************/
UInt32 deadKeyState = 0;
UniCharCount actualCount = 0;
UniChar baseChar;
TISInputSourceRef sourceRef = TISCopyCurrentKeyboardLayoutInputSource();
CFDataRef keyLayoutPtr = (CFDataRef)TISGetInputSourceProperty( sourceRef, kTISPropertyUnicodeKeyLayoutData );
CFRelease( sourceRef );
UCKeyTranslate( (UCKeyboardLayout *)CFDataGetBytePtr( keyLayoutPtr ), keyCode, kUCKeyActionDown, 0,
LMGetKbdLast(), kUCKeyTranslateNoDeadKeysBit, &deadKeyState, 1, &actualCount, &baseChar );
return baseChar;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment