Fix incorrect Unicode key mapping on Windows

This commit is contained in:
Naoto Kondo
2024-12-31 06:31:36 +09:00
parent 2582793d40
commit 8c7319459b

View File

@ -5787,7 +5787,12 @@ void DisplayServerWindows::_process_key_events() {
if (!(ke.lParam & (1 << 24)) && ToUnicodeEx(extended_code, (ke.lParam >> 16) & 0xFF, keyboard_state, chars, 255, 4, GetKeyboardLayout(0)) > 0) {
String keysym = String::utf16((char16_t *)chars, 255);
if (!keysym.is_empty()) {
key_label = fix_key_label(keysym[0], keycode);
char32_t unicode_value = keysym[0];
// For printable ASCII characters (0x20-0x7E), override the original keycode with the character value.
if (Key::SPACE <= (Key)unicode_value && (Key)unicode_value <= Key::ASCIITILDE) {
keycode = fix_keycode(unicode_value, (Key)unicode_value);
}
key_label = fix_key_label(unicode_value, keycode);
}
}
@ -5843,7 +5848,12 @@ void DisplayServerWindows::_process_key_events() {
if (!(ke.lParam & (1 << 24)) && ToUnicodeEx(extended_code, (ke.lParam >> 16) & 0xFF, keyboard_state, chars, 255, 4, GetKeyboardLayout(0)) > 0) {
String keysym = String::utf16((char16_t *)chars, 255);
if (!keysym.is_empty()) {
key_label = fix_key_label(keysym[0], keycode);
char32_t unicode_value = keysym[0];
// For printable ASCII characters (0x20-0x7E), override the original keycode with the character value.
if (Key::SPACE <= (Key)unicode_value && (Key)unicode_value <= Key::ASCIITILDE) {
keycode = fix_keycode(unicode_value, (Key)unicode_value);
}
key_label = fix_key_label(unicode_value, keycode);
}
}