[SDL] My thoughts on keyboard input in SDL 1.3
bob at pendleton.com
Sat Jan 19 09:52:24 PST 2008
On Sat, 2008-01-19 at 18:17 +0100, Gerry JJ wrote:
> Den Fri, 18 Jan 2008 17:12:15 -0600
> skrev Bob Pendleton <bob at pendleton.com>:
> > Trouble is that "Z" and some other keys move around from keyboard to
> > keyboard. In SDL1.3 SDLK_Z is supposed to be the key on the bottom row
> > of characters just to the right of the shift key no matter what is
> > printed on that key.
> You probably already know this, but that's not entirely accurate.. On
> my keyboard, and all other norwegian keyboards I've ever seen, the key
> just to the right of the left shift key is the '<' key (shift for '>'),
> and then the 'z' key is to the right of that. Of course, you already
> mentioned that keyboard layouts differ, but it brings up a point, if
> you bear with me for a little bit..
> A standard US keyboard doesn't have all the keys that keyboards from
> other layouts have, like the aforementioned '<' key. On the other hand
> it has some keys that other layouts may not have, like the '\' key under
> the backspace key (that key doesn't exist on norwegian keyboards,
> we've got a double-height and more narrow enter key in stead, making
> room for another (different) extra key on the row below).
Thank you for helping me make this point. I believe that you are
mistaking the location of the key and the symbol printed on the key. In
fact, SDL *should* return SDLK_Z for the key < key on a Norwegian
keyboard. SDLK_Z is not meant to tell us anything about what is
*printed* on the key, it only gives us its location. Sadly, the location
information is encoded using the key symbols for a US keyboard. I think
it might be easier if they were just SDLK_1....SDLK_258 then people
would only get confused by the first 9 SDLK names and wonder where zero
On keyboards that have keys in locations where the US keyboard does not
have a key SDL should return an SDLK_* that represents that extra
location on those key boards.
The new text input event returns the text encoded by a sequence of key
presses and on a Norwegian keyboard it would return < at the same time
that a key press event is returning SDLK_Z.
This problem, the difference between a keys location and the symbol
printed on it, is why we need to have a function to map SDLK_* values to
the symbols printed on the key caps. That function needs to return a
Unicode code point because a physical key might have a <, a Z, or a
Farsi, Korean, Chinese ... character printed on top of it, if possible.
> Also, some keys that are available with a single keypress on a US
> layout may not be on other layouts. On an US layout you can just hit
> the top left key to get a tilde. On the layout I'm using, to actually
> write a tilde, you need to hold Alt Gr and press the rightmost key on
> the second row *twice*. (That's the key just left of the upper half of
> enter. You can also press space in stead of the second press).
> So, a US keyboard both contain "extra" keys and are missing other
> keys compared to some other layouts. If a game wants to use the
> physical '\' key as on an US keyboard, I'd be out of luck since there's
> no such key on my keyboard. Similarly, if a game wants to use the key
> labelled '~', that might be problematic. Other layouts would have
> similar issues, not to mention small keyboards for handheld devices and
> such that butcher the standard layouts completely..
> Still, you've probably got to use *something* as a base, and the
> standard US layout may be as good as any..
> However, what if I wanted to use the physical '<' key on my keyboard,
> or any other key that doesn't exist on a standard US layout?
No problem, you would just look for SDLK_Z and it will work. The idea is
to let you have to kinds of input, one based on the position of the key
and one based on the symbol on the key. If you always want to use the
key in the *position* of your < key you would look in key pressed events
for SDLK_Z and if you want to use the < symbol in your code you would
look for '<' in text input events.
> seems no different than if I'd wanted to use the physical '\' key
> on a US layout. Using those keys would obviously be specific to that
> physical layout, but if I had some reason to want to do it anyway, I
> hope SDL would support it?
> I guess the point I'm trying to make is that these extra keys have
> standard positions for the layouts that have them, though different
> layouts may have different extra keys. To support them all would
> require some sort of superset of all the layouts, something that knows
> of the presence of both the '|' key under the backspace key on the US
> layout, the more narrow enter key and extra keys on mine, and all the
> others as far as it's possible to combine them all.
> - Gerry
You point is absolutely valid and we are trying to solve it using to
different kinds of input, one based on key position and one based on key
> SDL mailing list
> SDL at lists.libsdl.org
+ Bob Pendleton: writer and programmer +
+ email: Bob at Pendleton.com +
+ web: www.GameProgrammer.com +
+ www.Wise2Food.com +
+ nutrient info on 7,000+ common foods +
More information about the SDL