diff options
author | Teddy Wing | 2018-11-05 04:47:47 +0100 |
---|---|---|
committer | Teddy Wing | 2018-11-05 04:47:47 +0100 |
commit | 2c4c9e9e750cfe8c78fc15e07a405cfeef46d5c8 (patch) | |
tree | d4f0f46639e19c68c95809a87cc1a100e05165a3 /lib | |
parent | db7b1896278cc4e0ff3e289b73d5e76d6ac9c8ee (diff) | |
download | DomeKey-2c4c9e9e750cfe8c78fc15e07a405cfeef46d5c8.tar.bz2 |
Remove lib/char_to_key_code.*
We don't need these functions any more now that key simulation is
handled by the Rust library. The files can be safely removed.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/char_to_key_code.h | 17 | ||||
-rw-r--r-- | lib/char_to_key_code.m | 70 |
2 files changed, 0 insertions, 87 deletions
diff --git a/lib/char_to_key_code.h b/lib/char_to_key_code.h deleted file mode 100644 index 40c0c10..0000000 --- a/lib/char_to_key_code.h +++ /dev/null @@ -1,17 +0,0 @@ -// -// char_to_key_code.h -// DomeKey -// -// Created by tw on 8/27/18. -// Copyright © 2018 tw. All rights reserved. -// - -#ifndef char_to_key_code_h -#define char_to_key_code_h - -#import <Carbon/Carbon.h> - -NSString* keyCodeToString(CGKeyCode keyCode); -NSNumber* charToKeyCode(const char c); - -#endif /* char_to_key_code_h */ diff --git a/lib/char_to_key_code.m b/lib/char_to_key_code.m deleted file mode 100644 index ab4da15..0000000 --- a/lib/char_to_key_code.m +++ /dev/null @@ -1,70 +0,0 @@ -#import "char_to_key_code.h" - -// Théo Winterhalter -// https://stackoverflow.com/users/1275975/th%c3%a9o-winterhalter -// https://stackoverflow.com/questions/1918841/how-to-convert-ascii-character-to-cgkeycode/33584460#33584460 - -NSString* keyCodeToString(CGKeyCode keyCode) -{ - TISInputSourceRef currentKeyboard = TISCopyCurrentKeyboardInputSource(); - CFDataRef uchr = - (CFDataRef)TISGetInputSourceProperty(currentKeyboard, - kTISPropertyUnicodeKeyLayoutData); - const UCKeyboardLayout *keyboardLayout = - (const UCKeyboardLayout*)CFDataGetBytePtr(uchr); - - if(keyboardLayout) - { - UInt32 deadKeyState = 0; - UniCharCount maxStringLength = 255; - UniCharCount actualStringLength = 0; - UniChar unicodeString[maxStringLength]; - - OSStatus status = UCKeyTranslate(keyboardLayout, - keyCode, kUCKeyActionDown, 0, - LMGetKbdType(), 0, - &deadKeyState, - maxStringLength, - &actualStringLength, unicodeString); - - if (actualStringLength == 0 && deadKeyState) - { - status = UCKeyTranslate(keyboardLayout, - kVK_Space, kUCKeyActionDown, 0, - LMGetKbdType(), 0, - &deadKeyState, - maxStringLength, - &actualStringLength, unicodeString); - } - if(actualStringLength > 0 && status == noErr) - return [[NSString stringWithCharacters:unicodeString - length:(NSUInteger)actualStringLength] lowercaseString]; - } - - return nil; -} - -NSNumber* charToKeyCode(const char c) -{ - static NSMutableDictionary* dict = nil; - - if (dict == nil) - { - dict = [NSMutableDictionary dictionary]; - - // For every keyCode - int i; - for (i = 0; i < 128; ++i) - { - NSString* str = keyCodeToString((CGKeyCode)i); - if(str != nil && ![str isEqualToString:@""]) - { - [dict setObject:[NSNumber numberWithInt:i] forKey:str]; - } - } - } - - NSString * keyChar = [NSString stringWithFormat:@"%c" , c]; - - return [dict objectForKey:keyChar]; -} |