From 2c4c9e9e750cfe8c78fc15e07a405cfeef46d5c8 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Mon, 5 Nov 2018 04:47:47 +0100 Subject: 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. --- lib/char_to_key_code.h | 17 ------------ lib/char_to_key_code.m | 70 -------------------------------------------------- 2 files changed, 87 deletions(-) delete mode 100644 lib/char_to_key_code.h delete mode 100644 lib/char_to_key_code.m (limited to 'lib') 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 - -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]; -} -- cgit v1.2.3