Merge pull request #101754 from bruvzg/vk_oem_only

[Windows] Override key codes with Unicode values for OEM keys only.
This commit is contained in:
Thaddeus Crews
2025-02-05 10:27:16 -06:00

View File

@ -5887,7 +5887,9 @@ void DisplayServerWindows::_process_key_events() {
Ref<InputEventKey> k;
k.instantiate();
Key keycode = KeyMappingWindows::get_keysym(MapVirtualKey((ke.lParam >> 16) & 0xFF, MAPVK_VSC_TO_VK));
UINT vk = MapVirtualKey((ke.lParam >> 16) & 0xFF, MAPVK_VSC_TO_VK);
bool is_oem = (vk >= 0xB8) && (vk <= 0xE6);
Key keycode = KeyMappingWindows::get_keysym(vk);
Key key_label = keycode;
Key physical_keycode = KeyMappingWindows::get_scansym((ke.lParam >> 16) & 0xFF, ke.lParam & (1 << 24));
@ -5900,7 +5902,7 @@ void DisplayServerWindows::_process_key_events() {
if (!keysym.is_empty()) {
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) {
if (is_oem && 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);
@ -5943,6 +5945,7 @@ void DisplayServerWindows::_process_key_events() {
k->set_window_id(ke.window_id);
k->set_pressed(ke.uMsg == WM_KEYDOWN);
bool is_oem = (ke.wParam >= 0xB8) && (ke.wParam <= 0xE6);
Key keycode = KeyMappingWindows::get_keysym(ke.wParam);
if ((ke.lParam & (1 << 24)) && (ke.wParam == VK_RETURN)) {
// Special case for Numpad Enter key.
@ -5961,7 +5964,7 @@ void DisplayServerWindows::_process_key_events() {
if (!keysym.is_empty()) {
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) {
if (is_oem && 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);