diff options
| author | nilennoct | 2015-02-07 01:43:16 +0800 |
|---|---|---|
| committer | nilennoct | 2015-02-07 01:43:16 +0800 |
| commit | d5e6ab5bad050d21d93781a5e4e8c6e60ca449e6 (patch) | |
| tree | 3d4694ba3deb88d398253473513c8542d6c85199 | |
| parent | 6e52b1f4753d8363c4ced6dd779ac92716e49fb0 (diff) | |
| download | DDHotKey-d5e6ab5bad050d21d93781a5e4e8c6e60ca449e6.tar.bz2 | |
Fix crash using non-unicode layouts
Fix crash using non-unicode layouts, such as Chinese or Japanese.
| -rw-r--r-- | DDHotKeyUtilities.m | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/DDHotKeyUtilities.m b/DDHotKeyUtilities.m index 4c44ac1..f298a43 100644 --- a/DDHotKeyUtilities.m +++ b/DDHotKeyUtilities.m @@ -97,6 +97,14 @@ NSString *DDStringFromKeyCode(unsigned short keyCode, NSUInteger modifiers) { TISInputSourceRef currentKeyboard = TISCopyCurrentKeyboardInputSource(); CFDataRef uchr = (CFDataRef)TISGetInputSourceProperty(currentKeyboard, kTISPropertyUnicodeKeyLayoutData); + + // Fix crash using non-unicode layouts, such as Chinese or Japanese. + if (!uchr) { + CFRelease(currentKeyboard); + currentKeyboard = TISCopyCurrentASCIICapableKeyboardLayoutInputSource(); + uchr = (CFDataRef)TISGetInputSourceProperty(currentKeyboard, kTISPropertyUnicodeKeyLayoutData); + } + const UCKeyboardLayout *keyboardLayout = (const UCKeyboardLayout*)CFDataGetBytePtr(uchr); if (keyboardLayout) { |
