Skip to content

Commit d65c07d

Browse files
committed
[Windows] Override key codes with Unicode values for OEM keys only.
1 parent 7b1ed52 commit d65c07d

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

platform/windows/display_server_windows.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5838,7 +5838,9 @@ void DisplayServerWindows::_process_key_events() {
58385838
Ref<InputEventKey> k;
58395839
k.instantiate();
58405840

5841-
Key keycode = KeyMappingWindows::get_keysym(MapVirtualKey((ke.lParam >> 16) & 0xFF, MAPVK_VSC_TO_VK));
5841+
UINT vk = MapVirtualKey((ke.lParam >> 16) & 0xFF, MAPVK_VSC_TO_VK);
5842+
bool is_oem = (vk >= 0xB8) && (vk <= 0xE6);
5843+
Key keycode = KeyMappingWindows::get_keysym(vk);
58425844
Key key_label = keycode;
58435845
Key physical_keycode = KeyMappingWindows::get_scansym((ke.lParam >> 16) & 0xFF, ke.lParam & (1 << 24));
58445846

@@ -5851,7 +5853,7 @@ void DisplayServerWindows::_process_key_events() {
58515853
if (!keysym.is_empty()) {
58525854
char32_t unicode_value = keysym[0];
58535855
// For printable ASCII characters (0x20-0x7E), override the original keycode with the character value.
5854-
if (Key::SPACE <= (Key)unicode_value && (Key)unicode_value <= Key::ASCIITILDE) {
5856+
if (is_oem && Key::SPACE <= (Key)unicode_value && (Key)unicode_value <= Key::ASCIITILDE) {
58555857
keycode = fix_keycode(unicode_value, (Key)unicode_value);
58565858
}
58575859
key_label = fix_key_label(unicode_value, keycode);
@@ -5894,6 +5896,7 @@ void DisplayServerWindows::_process_key_events() {
58945896
k->set_window_id(ke.window_id);
58955897
k->set_pressed(ke.uMsg == WM_KEYDOWN);
58965898

5899+
bool is_oem = (ke.wParam >= 0xB8) && (ke.wParam <= 0xE6);
58975900
Key keycode = KeyMappingWindows::get_keysym(ke.wParam);
58985901
if ((ke.lParam & (1 << 24)) && (ke.wParam == VK_RETURN)) {
58995902
// Special case for Numpad Enter key.
@@ -5912,7 +5915,7 @@ void DisplayServerWindows::_process_key_events() {
59125915
if (!keysym.is_empty()) {
59135916
char32_t unicode_value = keysym[0];
59145917
// For printable ASCII characters (0x20-0x7E), override the original keycode with the character value.
5915-
if (Key::SPACE <= (Key)unicode_value && (Key)unicode_value <= Key::ASCIITILDE) {
5918+
if (is_oem && Key::SPACE <= (Key)unicode_value && (Key)unicode_value <= Key::ASCIITILDE) {
59165919
keycode = fix_keycode(unicode_value, (Key)unicode_value);
59175920
}
59185921
key_label = fix_key_label(unicode_value, keycode);

0 commit comments

Comments
 (0)