Skip to content

Commit 8c73194

Browse files
committed
Fix incorrect Unicode key mapping on Windows
1 parent 2582793 commit 8c73194

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

platform/windows/display_server_windows.cpp

+12-2
Original file line numberDiff line numberDiff line change
@@ -5787,7 +5787,12 @@ void DisplayServerWindows::_process_key_events() {
57875787
if (!(ke.lParam & (1 << 24)) && ToUnicodeEx(extended_code, (ke.lParam >> 16) & 0xFF, keyboard_state, chars, 255, 4, GetKeyboardLayout(0)) > 0) {
57885788
String keysym = String::utf16((char16_t *)chars, 255);
57895789
if (!keysym.is_empty()) {
5790-
key_label = fix_key_label(keysym[0], keycode);
5790+
char32_t unicode_value = keysym[0];
5791+
// For printable ASCII characters (0x20-0x7E), override the original keycode with the character value.
5792+
if (Key::SPACE <= (Key)unicode_value && (Key)unicode_value <= Key::ASCIITILDE) {
5793+
keycode = fix_keycode(unicode_value, (Key)unicode_value);
5794+
}
5795+
key_label = fix_key_label(unicode_value, keycode);
57915796
}
57925797
}
57935798

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

0 commit comments

Comments
 (0)