Skip to content

Conversation

@jedenastka
Copy link
Contributor

On Windows, keyboard events with an extended 0 Windows scancode are now processed by mapping the virtual-key code to a Windows scancode using the Win32 MapVirtualKey function.

Some keyboard scancodes (in particular, ones used for some non-typical keys) are not mapped to corresponding Windows scancodes, and are instead mapped to an extended 0 Windows scancode, with the distinction being only in the virtual-key code.

This causes GLFW to report a 256 GLFW scancode (0x00 | 0x100, 0x100 being the extended bit bitmask) for any of those keys, which causes API consumers to be unable to distinguish between them.

There exists, however, a Win32 function MapVirtualKey that maps those virtual key-codes to proper Windows scancodes. GLFW even appears to use this workaround, but after further inspection, it checks whether the Windows scancode is 0 (0x00), and not extended 0 (0x100).

This change makes GLFW check for the extended 0 keycode instead, which seems to work correctly. I'm not sure if checking for the non-extended 0 Windows scancode was intentional, as I never seem to have encountered one during testing with multiple keyboards. Thus, the handling of the non-extended 0 Windows scancode was removed, but it can be brought back if necessary.

I'd like to know if I'm correct in the assumption that it was not intentional, if I'm wrong I will add another commit to also have the old behavior.

Thanks to @muzikbike for providing help in testing this, including a Windows environment and various keyboards.

@elmindreda elmindreda added bug Bug reports and bugfix pull requests Windows Win32 specific (not Cygwin or WSL) input Keyboard, joystick or mouse labels Nov 21, 2023
@elmindreda elmindreda added this to the 3.5 milestone Feb 2, 2024
On Windows, keyboard events with an extended 0 Windows scancode are now
processed by mapping the virtual-key code to a Windows scancode using
the Win32 MapVirtualKey function.

Some keyboard scancodes (in particular, ones used for some non-typical
keys) are not mapped to corresponding Windows scancodes, and are instead
mapped to an extended 0 Windows scancode, with the distinction being
only in the virtual-key code.

This causes GLFW to report a 256 GLFW scancode (0x00 | 0x100, 0x100
being the extended bit bitmask) for any of those keys, which causes API
consumers to be unable to distinguish between them.

There exists, however, a Win32 function MapVirtualKey that maps those
virtual key-codes to proper Windows scancodes. GLFW even appears to use
this workaround, but after further inspection, it checks whether the
Windows scancode is 0 (0x00), and not extended 0 (0x100).

This change makes GLFW check for the extended 0 keycode instead, which
seems to work correctly. I'm not sure if checking for the non-extended 0
Windows scancode was intentional, as I never seem to have encountered
one during testing with multiple keyboards. Thus, the handling of the
non-extended 0 Windows scancode was removed, but it can be brought back
if necessary.
@jedenastka jedenastka force-pushed the extended-scancode-0 branch from b168c47 to 7235ddd Compare April 4, 2025 00:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Bug reports and bugfix pull requests input Keyboard, joystick or mouse Windows Win32 specific (not Cygwin or WSL)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants