[SDL] No unicode information in key releases
xavier.joubert at free.fr
Fri Jan 21 14:41:33 PST 2005
Selon Koshmaar <koshmaar at poczta.onet.pl>:
> In short: I know that I can't get unicode information from key releases. I
> know ugly solution to make this work (switching between 2 modes etc. as
> explained in first letter). I know that on SDL mailing list there are whole
> lots of advanced programmers who are writing games using SDL and event based
> input; it would be unbelievable if no one has ever encountered this problem
> (at least) and solved it (that's why I'm writing here and what I'm interested
> in). Are there any... hmmm, hacks which I could use?
There's no hack. Nobody store keypresses in an array for use with a GUI like you
Handling keyboard for a GUI and game control are two different things.
In a game context, whenever a key is pressed, you store in a array the fact the
key is down, so you will react accordingly in your input handling code as long
as it is not released. For example, if left is down, you will move player some
pixels to the left. When the key is released, you clear its state. That's what
you're doing in your code.
In a GUI context, whenever a key is pressed, you react to that event. If left is
pressed, you move cursor one char to the left. That's it. You don't need to
store anything or even handle SDL_KEYUP events. Of course, you need to use
SDL_EnableUNICODE() to get usuable infos. You will also use
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL), to
properly handle key repeat.
So, you need to switch from one mode to the other depending on the context. For
example when you see in your main game loop that user pressed, say, F12, then
you clear all key pressed, set a flag saying you're in GUI mode, and draw your
dialog box. Depending on the type of game (realtime or not), you will go to
another loop (in which case the games is paused) or continue in the main one,
but handling keyboard differently since you're in GUI mode.
More information about the SDL