Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions src/macos/keycode.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,22 @@ MMKeyCode keyCodeForChar(const char c)
CFStringRef string = createStringForKey((CGKeyCode)i);
if (string != NULL)
{
CFDictionaryAddValue(charToCodeDict, string, (const void *)i);
CFDictionaryAddValue(charToCodeDict, string, (const void *)(uintptr_t)i);
CFRelease(string);
}
}
}

charStr = CFStringCreateWithCharacters(kCFAllocatorDefault, &character, 1);

/* Our values may be NULL (0), so we need to use this function. */
if (!CFDictionaryGetValueIfPresent(charToCodeDict, charStr,
(const void **)&code))
/* Our values may be NULL (0), so we need to use this function.
* Use void* to match pointer size on 64-bit systems, then cast to CGKeyCode. */
void *value = NULL;
if (CFDictionaryGetValueIfPresent(charToCodeDict, charStr, (const void **)&value))
{
code = (CGKeyCode)(uintptr_t)value;
}
else
{
code = UINT16_MAX; /* Error */
}
Expand All @@ -56,9 +61,18 @@ MMKeyCode keyCodeForChar(const char c)
CFStringRef createStringForKey(CGKeyCode keyCode)
{
TISInputSourceRef currentKeyboard = TISCopyCurrentASCIICapableKeyboardInputSource();
if (currentKeyboard == NULL) {
return NULL;
}

CFDataRef layoutData =
TISGetInputSourceProperty(currentKeyboard,
kTISPropertyUnicodeKeyLayoutData);
if (layoutData == NULL) {
CFRelease(currentKeyboard);
return NULL;
}

const UCKeyboardLayout *keyboardLayout =
(const UCKeyboardLayout *)CFDataGetBytePtr(layoutData);

Expand Down