From 8c7319459b6f73f7a649ab16da4e2ad4c0ad7eeb Mon Sep 17 00:00:00 2001 From: Naoto Kondo Date: Tue, 31 Dec 2024 06:31:36 +0900 Subject: [PATCH] Fix incorrect Unicode key mapping on Windows --- platform/windows/display_server_windows.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp index 3c1a3915217a..a057fb508dc3 100644 --- a/platform/windows/display_server_windows.cpp +++ b/platform/windows/display_server_windows.cpp @@ -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); } }