1.3 proposals (was: Re: [SDL] LoadLibrary analogous function?)

John R. Hall overcode at lokigames.com
Wed Aug 29 19:31:02 PDT 2001

On Wednesday, August 29, 2001, at 07:15 PM, Standa Opichal wrote:

> On Wed, 29 Aug 2001, winterlion wrote:
>> [clip]
>>> I'd like to see the multidriver (portable) keykodes. The SDLK_ constants
>>> should be the scancode ekvivalents immutable with driver/platform 
>>> chages.
>>> There should be other API to get the character code of the key pressed
>>> (these are two differrent things). Now the SDLK_ returned changes e.g.
>>> with keyboard layout which is not good e.g. for emulator or games.
>> May not be possible.  Actually I suspect it isn't...  scancodes are
>> hardware-dependant and so are what keys present.  It also somewhat varies
>> with language...  and then there's the weird keyboards like the main one 
>> I
>> use (Microsoft Natural Pro USB) which has about 19 extra keys and the
>> Chinese one I play with from time to time.  (no extra keys but almost
>> every key lists 3-4 characters more than the standard).  There's the
>> European keyboards, which tend to occasionally move scancodes around, and
>> who can forget Dvorak? :)
> Well, Xes (X windows) does this pretty well, doesn't they?
> I think Xes does have "multikeyboard" scancodes. I think there should be
> as many SDLK_ s as there exists particular keys on all keyboards. The
> scancodes conversion should do the OS, doesn't it? Another conversion does
> Xes.
> BTW: There was a thread a month ago where someone agreed with this
> proposal.

For what it's worth: There are several layers of keyboard code mapping.

kscan codes - physical scancodes reported by the keyboard to the 
controller over the serial link. You never see these, but if you really 
wanted to, you could get them if you knew where to look.
scancodes - somewhat system-dependent multi-byte codes reported by the 
hardware to the OS.
keycodes - 8-bit codes reported by the kernel in raw or mediumraw modes. 
High bit is press/release, lower 7 bits are the key number. This is where 
keymaps come in. Note that the X Window System IGNORES keycodes entirely 
and performs its own scancode processing. This is why console keymaps don'
t have any effect in X. There are also 8 bits of modifier flags, to handle 
shift, alt, control, and various international keys.

If I recall correctly, the SDLK_ constants map to keycodes. SDL queries 
the kernel for the meaning of keycodes to handle internationalization.

Chapter 8 of Programming Linux Games discusses this whole mess.


John R. Hall |  Overfull \brain has occurred while \learn is active
CS Student - Georgia Tech  |  Author - Programming Linux Games
Unsolicited commerical e-mail will be considered an act of war.

More information about the SDL mailing list