Multiple key pushes in SDL

Hello All,

I’ve got a small problem concerning SDL and multiple key pushes.
Atm I’m writing a programm (emulator) which requires multiple key pushes.
For instance, I’m playing an racing game. I want to throttle using the UP
button (SDLK_UP) and steer using right and left.

Only when I push up and then try to steer then the up button is
not active anymore (whilst it is pushed)! I need to push the up
button again to make speed. I used the examples from the Key event but
somehow I just can’t get it working.

How can I make sure that the button pushes stays in the event queue
when other buttons are pressed?

If somebody has a idea, please give me your knowledge.

Thanks in advance.

Regards,

Niels Wagenaar

> Only when I push up and then try to steer then the up button is > not active anymore (whilst it is pushed)! I need to push the up > button again to make speed. I used the examples from the Key event but > somehow I just can't get it working.

What I do is have a number of flags that I turn on and off depending on
if I get a “KeyPress” or “KeyRelease” event from SDL regarding that key.

I think also there’s a function you can call which simply tells you the
state (pressed or released) of a particular key.

Good luck!

-bill!On Tue, Aug 14, 2001 at 01:24:13AM +0200, nwagenaar at digitaldynamics.nl wrote:

First, be aware that certain key combinations cannot be registered by PC
keyboards, due to hardware limitations in the keyboard itself.

In a game that is based on holding keys down, it is probably best to merely
set a flag in the event handler when a keypress is received. Some other code
which runs in your main loop should act on those flags. When the key is
released (another event), clear the flag.

So if the user presses the UP key, it might set the ‘up_pressed’ flag, and if
the user presses the LEFT key, it might set the ‘left_pressed’ flag. The game
logic can then act on both of those flags to determine what happens.

-RayOn Monday 13 August 2001 19:24, you wrote:

Hello All,

I’ve got a small problem concerning SDL and multiple key pushes.
Atm I’m writing a programm (emulator) which requires multiple key pushes.
For instance, I’m playing an racing game. I want to throttle using the UP
button (SDLK_UP) and steer using right and left.

Only when I push up and then try to steer then the up button is
not active anymore (whilst it is pushed)! I need to push the up
button again to make speed. I used the examples from the Key event but
somehow I just can’t get it working.

How can I make sure that the button pushes stays in the event queue
when other buttons are pressed?

If somebody has a idea, please give me your knowledge.

Hallo!

There is some function called SDL_GetKeyState or something like this. I don’t
remeber the whole name(loook in the doc’s).
This funktion gives you a pointer to a table where the states of all key’s
are stored.
So you only have to check at the beginning of your main loop of the key is
pressed by indexing this array.

Alil

nwagenaar at digitaldynamics.nl wrote:> Hello All,

I’ve got a small problem concerning SDL and multiple key pushes.
Atm I’m writing a programm (emulator) which requires multiple key pushes.
For instance, I’m playing an racing game. I want to throttle using the UP
button (SDLK_UP) and steer using right and left.

Only when I push up and then try to steer then the up button is
not active anymore (whilst it is pushed)! I need to push the up
button again to make speed. I used the examples from the Key event but
somehow I just can’t get it working.

How can I make sure that the button pushes stays in the event queue
when other buttons are pressed?

If somebody has a idea, please give me your knowledge.

Thanks in advance.

Regards,

Niels Wagenaar


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Atm I’m writing a programm (emulator) which requires multiple key pushes.

I hate to be a single issue poster, but to warn you in advance if it
confuses you for days as it confused me - caps lock and num lock don’t
generate key up/down events the same way as the rest of the keyboard do,
since on some exotic machines (SunOS I think was the example) that would be
impossible.

-Thomas