Fixed key names when KEYCODE_OPTION_LATIN_LETTERS is enabled

This commit is contained in:
Sam Lantinga 2024-08-05 09:16:43 -07:00
parent a82f19f690
commit b7aca89466

View File

@ -1010,19 +1010,16 @@ const char *SDL_GetKeyName(SDL_Keycode key)
// SDL_Keycode is defined as the unshifted key on the keyboard,
// but the key name is defined as the letter printed on that key,
// which is usually the shifted capital letter.
if (key > 0x7F || (key >= 'a' && key <= 'z')) {
SDL_bool translated = SDL_FALSE;
if (key >= 'a' && key <= 'z') {
key = 'A' + (key - 'a');
} else if (key > 0x7F) {
SDL_Scancode scancode = SDL_GetScancodeFromKey(key, SDL_KMOD_NONE);
if (scancode != SDL_SCANCODE_UNKNOWN) {
SDL_Keycode capital = SDL_GetKeyFromScancode(scancode, SDL_KMOD_SHIFT);
if (capital > 0x7F || (capital >= 'A' && capital <= 'Z')) {
key = capital;
translated = SDL_TRUE;
}
}
if (!translated && key >= 'a' && key <= 'z') {
key = 'A' + (key - 'a');
}
}
end = SDL_UCS4ToUTF8(key, name);