Accounting for the keyboard layout while using SDL on Mac OS X seems
to be an exercise in frustration, and I wonder if anybody else has
been encountering the problems that I’ve been having.
My system language is set to Italian, while my keyboard layout is set
to U.S. Dvorak. The problem I’m having is that the key syms that SDL
generates for keyboard events seem to be dependent upon the system
language that you’ve chosen.
Typically, when using a QWERTY keyboard, pressing Q on the keyboard
will generate an SDL event with the key sym SDLK_q, pressing R will
give the sym SDLK_r, etc. On my system, however, this is slightly
different. SDL seems to assume I am using the Italian QZERTY keyboard
layout, and so when I press the w key, I get an SDLK_z key sym instead!
So, assuming that the key syms that SDL generates are under the QWERTY
keyboard layout is a bad assumption, and therefore we can’t translate
keys based solely on the key syms.
We tried using the Unicode keys, but this runs into a different
problem; unicode variables are not sent along with keyboard events
that signal a key has been unpressed, only the key syms! And since
the key syms aren’t reliable, there seems to be no reliable way to
figure out exactly which key has been unpressed (which is crucial,
since this is a game that is using SDL, and movement needs to stop as
soon as a key is unpressed).
What’s the solution to this problem? Is there a way to get stable key
syms that don’t change based on the system language setting?
Even better, is there a way for SDL to automatically take into account
the keyboard layout of the system and generate the appropriate key
syms automatically without my own code having to translate between
QWERTY and the selected keyboard layout?
Any help would be greatly appreciated.
– Simone