Skip to content
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

KEY_BRACKETLEFT and KEY_BRACELEFT are mixed up on Windows #54958

Closed
juanitogan opened this issue Nov 14, 2021 · 1 comment · Fixed by #56514
Closed

KEY_BRACKETLEFT and KEY_BRACELEFT are mixed up on Windows #54958

juanitogan opened this issue Nov 14, 2021 · 1 comment · Fixed by #56514

Comments

@juanitogan
Copy link
Contributor

Godot version

3.3.4 and 3.4

System information

Windows 10, US QWERTY keyboard

Issue description

The [ key on a US QWERTY keyboard reports as KEY_BRACELEFT instead of KEY_BRACKETLEFT from InputEventKey.scancode. The same is true for the new physical_scancode prop as well. This mixup also applies to the right bracket ] (KEY_BRACKETRIGHT/KEY_BRACERIGHT).

This is on Windows for a Windows build (plus running from in editor, of course). And, yet, on an HTML5 build, [ reports correctly as KEY_BRACKETLEFT in a browser. (Except when hitting Shift+[ in a browser which reports as KEY_BRACELEFT -- which is, uh, maybe a browser quirk? Ignore that for now perhaps.)

Steps to reproduce

Here's a code fragment:

func _input(event):
	var code : int
	if event is InputEventKey and not event.echo:
		code = event.scancode
		#code = event.physical_scancode
	else:
		return
	match code:
		#KEY_BRACKETLEFT: # [  (BUG: does not work on windows, shift+[ does not work in browser)
		KEY_BRACELEFT: # {  (BUG: [ on win, shift+[ on browser)
			print(code)

Minimal reproduction project

No response

@akien-mga
Copy link
Member

Indeed, the key mapping seems off, this would probably fix it:

diff --git a/platform/windows/key_mapping_windows.cpp b/platform/windows/key_mapping_windows.cpp
index d84e156ab6..a520cbd8dc 100644
--- a/platform/windows/key_mapping_windows.cpp
+++ b/platform/windows/key_mapping_windows.cpp
@@ -217,9 +217,9 @@ static _WinTranslatePair _vk_to_keycode[] = {
        { KEY_SLASH, VK_OEM_2 }, // (0xBF) //Windows 2000/XP: For the US standard keyboard, the '/?' key
 
        { KEY_QUOTELEFT, VK_OEM_3 }, // (0xC0)
-       { KEY_BRACELEFT, VK_OEM_4 }, // (0xDB)
+       { KEY_BRACKETLEFT, VK_OEM_4 }, // (0xDB)
        { KEY_BACKSLASH, VK_OEM_5 }, // (0xDC)
-       { KEY_BRACERIGHT, VK_OEM_6 }, // (0xDD)
+       { KEY_BRACKETRIGHT, VK_OEM_6 }, // (0xDD)
        { KEY_APOSTROPHE, VK_OEM_7 }, // (0xDE)
        /*
 {VK_OEM_8 (0xDF)

The whole list might be worth reviewing and checking against https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes, it's fairly old code and might have other yet unnoticed bugs or missing bits. CC @godotengine/windows @bruvzg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment