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
Windows and Mac OS X keyboard drivers don't honor layout while the GNU/Linux one does #723
Comments
This is by design. Basically the KEY_* constants are random and you have to allow the user to assign them (you can use al_keycode_to_name() to help with that). However, in practice, on Windows/OSX it is easy to get the hardware keycode, which is independent of the layout. And so KEY_* constants largely correspond to the physical positions of a US keyboard there. On X11, there seems to be no obvious way to get those codes, and so keys are mapped to what the layout says. Personally I think the Linux way is better - and we /could/ change Windows/OSX to do the same. People using a US keyboard would not see any change at all. However for everyone else using Windows/OSX and having a game with hardcoded keys it would suddenly break it - so it may not be a good idea to change this at this point. |
When you say "user" are you referring to the user of the game which uses Allegro? MININIM uses hard coded keys and changing Windows and Mac OX X drivers to behave like the GNU/Linux one would simply fix it. If such a change happens to break someone's else game, it's because it broke an already broken game, fixing it in effect, because developers using hard coded keys can't presuppose everyone else has the same keyboard layout. It's natural to expect that Allegro respects the keyboard layout. I think this would be a change for the better. |
I think @allefant means that the game isn't supposed to hardcode the keys at all - you're supposed to allow the user to remap them in the same way you have to allow remapping joystick buttons. As for breaking hardcoded games, that's referring to games that map to, e.g. QWERTY Z and X (or A and S), having Allegro suddenly use the physical keyboard layout might move those to inconvenient locations. Players would almost certainly consider that a regression. That said, this is inconvenient for games using the keyboard routines for actual text input. So even though it has the potential to break existing games, I ultimately vote for fixing it too. |
In terms of changing this, we'll probably have a config option (want_old_style_keycodes) set to true and people can opt into the new 'fixed behavior'. That said, I think it's the Linux behavior that's wrong. Conceptually, the mechanics of human hands are international, so if you want to hardcode keys you probably want them to be in the same general area of the keyboard rather than matching some arbitrary key stickers. E.g. WASD should be a cluster of keys on the left of the keyboard no matter the layout. To that end, I think keycodes should be layout independent, if possible. The intended way to use keycodes is to go through |
As mentioned above, the Windows/OSX behavior is inconvenient for games using the keyboard routines for actual typing (e.g. "enter character name" type screens), since the game has no way of knowing the physical layout. That can be "fixed" by having the player remap them all to their real mappings, but that'd be a nuisance if every non-US player had to do that before they could even play the game. Unless |
For text input you use ALLEGRO_EVENT_KEY_CHAR and ALLEGRO_EVENT_KEY_CHAR only, which always will give you the correct unicode. |
Thanks for that tip; I'm using |
I see. It seems once more I misunderstood an Allegro feature. So the purpose of key codes is actually to have a layout-free reference to keys (a physical/universal layout instead of a label-based/relative one). If that's the case, I agree that the GNU/Linux behavior is wrong. PS: Key codes having meaningful (enumeration) names certainly adds up to that misunderstanding. |
I gather that the Allegro key codes are meant to be an analogue to hardware scan codes, which are also layout-agnostic. As for the enumeration, the constants had to be given meaningful names one way or another - so US QWERTY names seem like a good reference point particularly since it's probably the layout most familiar to programmers. |
Not really. KEY0, KEY1, KEY2... |
Well at that point one may as well use the scancodes directly, no? :) Even so I much prefer that the enumeration uses the QWERTY-names rather than just numbered codes. Even if QWERTY isn't your native layout you can map them back to a diagram of one. Otherwise you'd have to remember where on the keyboard each numbered code corresponds to. |
But anyway, I agree that the behavior should at least be consistent across all platforms, which it currently isn't. |
The allegro keycodes not varying for the keys in the same physical position is not necessarily a problem but the failure to return a keycode at all for key physically present on non-US keyboard but not on the US keyboard is an issue as without a keycode being returned it impossible for the application using Allegro to map it to anything. As an example, I have the UK layout and there is key to the left of the 1 key. If I tap this key and log the keyboard events received I get no key down event but I do get a key up event with a code of zero. |
What system do you have? This is something we should be able to fix more easily than this bug. |
It's Windows 10 running within VirtualBox.
and tapping that key gives:
running the same test program on GNU/Linux (Arch), Allegro 5.2.3.1 gives:
In keycodes.h code 60 is ALLEGRO_KEY_TILDE which makes sense as this key on the UK keyboard is in physically the same place as the ~ key on a US keyboard. |
Under windows this table is used, as you can see several entries have a 0: https://github.com/liballeg/allegro5/blob/master/src/win/wkeyboard.c#L39 All we need is figure out which entry your key produces and put in some unused ALLEGRO_* code (or a new one). |
ALLEGRO_KEY_TILDE would be produced for the Windows keycode 192 (0xC0). Somehow your key must produce something else. |
One last thing, what is your host operating system? Google finds a lot of people who cannot use the tilde key when running a Windows guest on an OSX host. |
The host is Linux, the same one that I have comparing with above. I was going to try compiling Allegro myself and and adding some debug to get the VK code but cmake just locks up when I try. Instead I found an example program on the net and hacked that so it would print the VK code:
That gives me
So that's DF (hex) for the problematic key which indeed maps to zero in that table. |
Having finally got cmake to work, putting ALLEGRO_KEY_UNKNOWN+39 in position DF in that table does the trick. |
In the past I've had some issues with tilde on macOS and experimental SDL backend on GNU/Linux. I think I have some workaround somewhere inside my engine. Let me check if those are still relevant! :) |
My keyboard has Brazilian ABNT 2 layout. In GNU/Linux Allegro key codes match their enumeration names with their respective symbols on the real keyboard as expected. For instance, ALLEGRO_KEY_OPENBRACE corresponds to the key immediately below equals and backspace keys, as shown in the picture linked above. On Windows and Mac OS X, however, that key corresponds to ALLEGRO_KEY_CLOSEBRACE, as one would expect for the US QWERTY layout. In general, it seems Allegro is interpreting key codes unconditionally based on US layout for both platforms, while in GNU/Linux it honors the current keyboard layout.
The text was updated successfully, but these errors were encountered: