Sam Lantinga wrote:
That’s correct. Anything else and it’s a bug; either in SDL’s drivers or
in the setup of your machine (probably the former)
Mattias, that’s actually not correct. There are several situations in
which the OS localized keyboard layout doesn’t affect the keysyms that
are generated by the hardware.
It does not change the fact that it’s completely bogus semantics.
SDLK_Y should not mean “the key that is located in roughly the same
position as the “Y” key on Sam’s own favourite keyboard that the user
has never seen in his life”; it’s not reasonable at all
Max has added a hack to handle this on
MacOS by introducing an additional keytable, but it’s not necessarily
an elegant solution. I believe the same thing happens when using DirectInput
on Windows, and when using the framebuffer console on Linux.
We should look into it solving it then (I haven’t seen Max’ hack)
Essentially the problem is that the keyboard scancodes map to a "standard"
set of keyboard keycodes which are completely separate from localized
keyboard text input translation.
It’s been discussed here before, and I believe the Right Solution
would be to de-couple keyboard codes (scancodes) from keysyms, a la X11,
so instead of
if(event->key.keysym.sym == SDLK_A) ...
you’d first look up the keycode for the “A” key:
SDL_keycode a_key = SDL_KeysymToKeycode(SDLK_A);
if(event->key.code == a_key) ...
so the event structure would not contain a keysym at all (just a keycode),
keycodes would be “dense” enough to be useful as array or bitvector
indices (in the range 0…255, say), and we can have proper keysyms for
any keys. This also provides a mean to find out whether a key actually
exists on the keyboard — it solves a lot of problems