Is it even possible to do anything else? I can’t imagine keyboards report their physical layout..
Is it even possible to do anything else? I can’t imagine keyboards report their physical layout..
Windows, macOS and the various input libraries on Linux provide ways to query the key map - and a number of games do use this to provide localized bindings (Ubisoft and Blizzard are notorious for doing this right, something I appreciate as a dvorak user who hates dealing with rebinding or constantly having to toggle layouts). As far as the browser there is coming support for reading the keyboard layout as well: https://developer.mozilla.org/en-US/docs/Web/API/Keyboard/ge...
If you type WASD on a US layout USB keyboard, the computer will receive key codes 26, 4, 22, 7.
If you type ZQSD on a French keyboard you get exactly the same result.
So if you are writing a game, you might listen for codes 26, 4, 22, 7 and these will be in the sample place on the keyboard regardless of layout. You can ask the OS to translate these codes to letters for help text.
(Some of the details here are omitted—the codes above are USB HID codes, but those go through an additional OS-specific translation table before they are sent to your program.)
It’s impossible to know the physical layout for absolute certainty. For all you know, my “Enter” could be a pedal under the desk.
https://www.x.org/releases/current/doc/libX11/XKB/xkblib.htm...
Other games like the Java version of minecraft didn't work with Dvorak when I tried them. Even with key remapping.
You can easily ask the OS what layout is being used or even ask the user.