Archived from groups: rec.games.roguelike.development (
More info?)
Christophe Cavalaria wrote:
> Krice wrote:
>
> > bamcquern@yahoo.com wrote:
> >> and ">" taking me downstairs.
> >
> > This is also true. But it seems that the keyboard routine of SDL
> > is fooled by different keyboards. In my finnish keyboard those
> > commands work. I don't know yet how to fix that...
>
> I see coming yet another game with broken international keyboard handling
> while using SDL
I swear the "examples" you can find in the user comments
> on the SDL documentation must be some kind of curse for us non english
> users !
>
> Use SDL_EnableUnicode( 1 ); to enable unicode translation and use the
> unicode field of the SDL_keysym struct you get with the keyboard event for
> all keys which return a valid symbol. The scancode field should never be
> used because it's very hardware specific and the sym field is unreliable
> for all keys except maybe F1-F12, arrow keys and letter keys where it's the
> only way to go. If you do some user editable keyboard configuration, you
> can use the sym field in a reliable way because all users should be able to
> redefine the missing keys then.
>
> Remember, is some keyboard, there is no SDLK_0-SDLK_9 keys, in some other
> keyboard it's the SDLK_GREATER which doesn't exist ...
Yes, the curse of SDL's keyboard handling...
I think I finally fixed it up with You Only Live Once (If anyone still
has keyboard troubles with the SDL version, please let me know!).
Please note that you still need to look at the scancode to catch
numberpad keys. Windows XP has an annoying habit of not setting the
unicode values for SDLK_KP*, requiring you to parse them manually.
The relevant code that I use is:
int
gfxsdl_cookkey(int unicode, int sdlkey)
{
if (unicode && unicode < 128)
return unicode;
switch (sdlkey)
{
// Insert several curses here... This isn't necessary
// anywhere except WIndows XP it seems...
case SDLK_KP0:
return '0';
case SDLK_KP1:
return '1';
case SDLK_KP2:
return '2';
case SDLK_KP3:
return '3';
case SDLK_KP4:
return '4';
case SDLK_KP5:
return '5';
case SDLK_KP6:
return '6';
case SDLK_KP7:
return '7';
case SDLK_KP8:
return '8';
case SDLK_KP9:
return '9';
case SDLK_UP:
return GFX_KEYUP;
case SDLK_DOWN:
return GFX_KEYDOWN;
case SDLK_LEFT:
return GFX_KEYLEFT;
case SDLK_RIGHT:
return GFX_KEYRIGHT;
}
return 0;
}
void
gfxsdl_pollEvents()
{
SDL_Event event;
while (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_KEYDOWN:
// For now, ignore arrow keys..
int key;
key = gfxsdl_cookkey(event.key.keysym.unicode,
event.key.keysym.
sym);
gfxsdl_putKey(key);
// Set the pusher.
glbKeyPusher = key;
glbKeyPushTime = gfxsdl_getframecount() +
KEY_REPEAT_INITIAL;
break;
case SDL_KEYUP:
// Stop the pusher.
glbKeyPusher = 0;
break;
case SDL_QUIT:
SDL_Quit();
exit(0);
break;
}
}
// Note that we handle key repeat here, not in the actual timer
loop!
// This way if our processing freezes, the key repeating also
// freezes.
{
int frame;
frame = gfxsdl_getframecount();
if (glbKeyPusher)
{
if (frame >= glbKeyPushTime)
{
gfxsdl_putKey(glbKeyPusher);
glbKeyPushTime = frame + KEY_REPEAT_AFTER;
}
}
}
}
I dump the keypresses onto a queue after I cook them, and the normal
getKey() function will grab from that queue.
--
Jeff Lait
(POWDER: http://www.zincland.com/powder)