Hi,
I have figured out some problems with key events. (Tested on SDL-1.2.11
and SDL-1.2.13 on Linux.)
I have written a very simple test-application, basically this:
int main() {
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE);
SDL_SetVideoMode(100, 100, 32, 0);
EventLoop();
SDL_Quit();
}
And in EventLoop() I just give information about all pressed and
released keys (I catch the SDL_KEYUP and SDL_KEYDOWN).
I did now the following:
- pressed SDLK_TOP
- pressed SDLK_LEFT
- pressed SDLK_RIGHT
- released SDLK_TOP
- released SDLK_LEFT
- released SDLK_RIGHT
I get this output (I have added some comments):______________
type: 2
state: 1
sym: 273 // TOP down
unicode: 0
mod: 0
scancode: 98
type: 2
state: 1
sym: 276 // LEFT down
unicode: 0
mod: 0
scancode: 100
RIGHT key is not recognised!
type: 2
state: 1
sym: 279 // wrong! (released TOP, it’s also not RIGHT=275)
unicode: 0
mod: 0
scancode: 103 // wrong!
type: 3
state: 0
sym: 276 // LEFT up
unicode: 0
mod: 0
scancode: 100
type: 3
state: 0
sym: 279 // wrong! (released RIGHT)
unicode: 0
mod: 0
scancode: 103
type: 3
state: 0
sym: 273 // LEFT? (app lost focus)
unicode: 0
mod: 0
scancode: 0
I can reproduce similar problems when I press the keys in another order.
Though it seems to work correct if I use keys A-Z.
I figured this problem out in a game where keys got recognised as
staying pressed while they are not (it results that the player for
example just keeps going left). I use SDL_GetKeyState() there.
Does somebody know this problem? Or does somebody have some hints why
this could happen?
And possible workarounds? In this demo app, it seems that loosing focus
try to fix something but in my game it doesn’t change anything (the
players keeps running). I even can keep multiple keys “pressed” (for
example left + up; if I press down then, the cursor keeps always going
up after and the players keeps running left).
I have also tested this on the same machine but under MacOSX and the
problem does not occur there (I am also using a SDL >=1.2.11 there).
Greetings,
Albert