Replies: 5 comments 8 replies
-
This issue might be related: glfw/glfw#1502 |
Beta Was this translation helpful? Give feedback.
-
@JeffM2501 That's an awesome breakdown of the considerations. Is there any straightforward way to have access to the platform's knowledge of the assumed keyboard layout, or does GetKeyName solve the problem? You introduce VirtualKeyCode. Is this like (Sorry, the terms being thrown around hurt my brain.) |
Beta Was this translation helpful? Give feedback.
-
@JeffM2501 https://github.com/glfw/glfw/blob/21fea01161e0d6b70c0c5c1f52dc8e7a7df14a50/src/win32_window.c#L684 Raylib already uses the character callback here: raylib/src/platforms/rcore_desktop_glfw.c Line 1815 in 1f704be Since Raylib's keys map to the ASCII chars (I think), it should be possible to use the character callback in order to get the keycode press. |
Beta Was this translation helpful? Give feedback.
-
what does the on screen keybboard use ?
https://support.microsoft.com/en-us/windows/use-the-on-screen-keyboard-osk-to-type-ecbb5e08-5b4e-d8c8-f794-81dbf896267a
https://youtu.be/ORhuppDoC1g?si=ZaKIuc33cGbPWkJN&t=25
…On Thu, Dec 12, 2024 at 2:33 PM Dennis E. Hamilton ***@***.***> wrote:
Yes, the prospect of scope creep here is worrisome. It might be necessary
to have a clear line in the sand so long as there is a way for folks
wanting to handle locality to do it themselves or with supplementary
libraries.
—
Reply to this email directly, view it on GitHub
<#4595 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AB3KGRZY6M6SVCXIDT4IOO32FHQHHAVCNFSM6AAAAABTQLWS4CVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTCNJUHA3DSNI>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
I have written up a small quick and dirty demo of showing the keyboard map with names and doing a keybinding type GUI. I think it shows that keyboard_settings_example.mp4
|
Beta Was this translation helpful? Give feedback.
-
Problem
The way that raylib currently handles input polling only allows users to poll keys using names from the US ASCII QUERTY layout, This can be confusing for people who have different keyboard layouts.
Terms
Before I start, I want to define some terms, because part of this issue is confusion in terms between different platforms.
Physical Key
This is the actual keyboard switch on the keyboard hardware. It is provided by the actual hardware device and does not know anything about locale or keyboard mapping. It represents a physical location on the keyboard, regardless of what is printed on the keycap.
Each of these keys has an ID. In the case of the 4 red keys, the IDs are 87,65,83, and 68.
Because of history, these codes happen to align with the ASCII characters for W A S, and D, but are considered OEM codes.
A different keyboard with a different layout like dvorak, will still return the same physical key codes for the same red keys.
This is because keyboard mapping is done at the OS level not the hardware level, you can take a QUERTY Keyboard and swap the keycaps around to DVORAK, but the physical switches in the hardware do not change what signals they send. These keys will still send 87,65,83, and 68 even though they are labeled as < A O and E.
Physical keys are useful for game inputs. In a FPS game the developer would want to default the controls to the red keys, regardless of keyboard layout, since that’s where the player’s left hand will sit. The use of physical key codes allows the developer to check the actual device and not have to worry about actual layout for these kinds of inputs.
Raylib’s KeyboardKey is the physical key code. The enums are named based on the US QUERTY layout.
Different platforms call this code different things.
Virtual Key Code
This is a code that unlike the physical key code, is mapped to the current OS keyboard layout. It returns a value based on what is printed on the key and what the OS uses when the keyboard is pressed. In the examples above, the red keys would return different values based on the keyboard layout.
A user may want to check for specific named keys, not just physical locations for specific types of input in the game.
Raylib does not expose the Virtual Key Code in any way.
GLFW has something called scancode that looks like it would be the mapped item, but it is not.
GLFW does not expose the virtual key in any way.
SDL exposes this as a virtual keycode.
Windows provides this as the 'VK' Code as part of the lParam in the keyboard event.
Key Character
The key character is the printable unicode character that is generated when a key/key combination is pressed by the user. It takes the keyboard mapping, locale, and key modifier states (shift and caps-lock) into account to generate a printable character.
This character is only available for keys that have printable characters, Key such as F1, escape, insert, and numlock, do not generate characters.
These characters are sent as part of input messages to the platform code, separate from the physical and virtual key codes.
Raylib exposes these to the game with the GetCharPressed event functions, and is the basis for all text input.
Keyboard Information Available
There are 4 pieces of info potentially available for each key.
Providing access to virtual mapped key codes
The big thing confusing people is that all the poll able codes in raylib are purely physical codes, there is no way to poll a virtual or mapped key. This makes people feel that raylib ‘only works with US keyboards’
I think part of this can be solved with education, making sure that people know that the KeyboardKey enum is physical keys, not virtual ones, since this is what most game input wants.
The recent addition of GetKeyName in 5.5 also allows people to use physical key codes and still provide a localized keymapping GUI, by simply asking what the display name of the key should be.
What we don’t provide is a way for people to truly poll the virtual key code. This would be a use case where someone wants to know when A is pressed, regardless of where A is on the keyboard. I’m not 100% sure this is a common use case. I think the major complaints were due to the lack of GetKeyName, but perhaps someone has a legit use case and can let us know.
Action Items
I think at the very least we need to make it clear in the header that KeyboardKey is a physical key. We should also maybe make an example that uses GetKeyName to show people how to get the mapped name for setup GUIs, perhaps something like the gamepad example but with keys.
If anyone has any use cases that require polling a virtual key, please respond here so we can discuss
Beta Was this translation helpful? Give feedback.
All reactions