internal bool KeycodeForChar(char Key, CGKeyCode *Keycode) { static CFMutableDictionaryRef CharToCodeDict = NULL; bool Result = true; UniChar Character = Key; CFStringRef CharStr; if (!CharToCodeDict) { CharToCodeDict = CFDictionaryCreateMutable(kCFAllocatorDefault, 128, &kCFCopyStringDictionaryKeyCallBacks, NULL); if (!CharToCodeDict) return false; for(std::size_t KeyIndex = 0; KeyIndex < 128; ++KeyIndex) { CFStringRef KeyString = KeycodeToString((CGKeyCode)KeyIndex); if (KeyString != NULL) { CFDictionaryAddValue(CharToCodeDict, KeyString, (const void *)KeyIndex); CFRelease(KeyString); } } } CharStr = CFStringCreateWithCharacters(kCFAllocatorDefault, &Character, 1); if (!CFDictionaryGetValueIfPresent(CharToCodeDict, CharStr, (const void **)Keycode)) Result = false; CFRelease(CharStr); return Result; }
const char *SaveKeycodes(const Hotkey<T> *hotkey) { static char buf[128]; buf[0] = '\0'; for (uint i = 0; i < hotkey->keycodes.Length(); i++) { const char *str = KeycodeToString(hotkey->keycodes[i]); if (i > 0) strecat(buf, ",", lastof(buf)); strecat(buf, str, lastof(buf)); } return buf; }