-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix incorrect Unicode key mapping on Windows #100960
base: master
Are you sure you want to change the base?
Conversation
23cf20d
to
6c128cf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you provide any extra details for the conditions when MapVirtualKey()
is not working properly (keyboard layout and specific keys not working)?
@@ -5787,6 +5787,8 @@ 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 unicode_keysym = KeyMappingWindows::get_unicode_keysym(keysym[0]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ASCII values are mapped to Godot key constants exactly, there's no need for the mapping:
Key unicode_keysym = KeyMappingWindows::get_unicode_keysym(keysym[0]); | |
Key unicode_keysym = (Key)keysym[0]; |
plus range check, since keycode
should not have other values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you.
Indeed, when Godot's key codes match ASCII key codes, no lookup table is needed.
6c128cf
to
4885ac6
Compare
@bruvzg Thank you for the review.
I am using a Japanese keyboard (jp106). There are some OEM key codes. Please refer to the following URL for details: |
4885ac6
to
8c73194
Compare
This PR fixes incorrect keycode mapping for Unicode input on Windows platform.
Details
When a key is pressed, MapVirtualKey() converts the scan code to a virtual key code. However, some converted virtual key codes are defined as OEM codes and do not take keyboard layout into account.
Although ToUnicodeEx() is then used to convert to actual Unicode characters, currently only key_label is updated while keycode remains unchanged.
To resolve this problem, we need to have a Unicode key mapping table and override Godot's key codes based on it.
Test project
debug_key.zip