Events (keyboard)

I noticed that SDL_PollEvent(&event) doesn’t seem to register an event if I
keep a key debounced (pushed down). Is there a good way to take care of
this? What I want to be able to do is continually read the event if the
user holds down a key, rather than just having him tap it repeatedly to get
an event signaled. Thanks… Right now I’m doing this:

SDL_Event event;
while ( SDL_PollEvent(&event) )
{
if ( event.type == SDL_QUIT )
{
exit = 1;
}
// exit
if ( event.key.state == SDL_PRESSED )
{
if ( event.key.keysym.sym == SDLK_ESCAPE )
{
exit = 1;
}
// move the model
if (event.key.keysym.sym == SDLK_r)
{
model1.translate(0, 0.1, 0);
}
}

-TP

Use this function:

extern void SDL_EnableKeyRepeat(int delay, int interval);

Of course, I think this only applies to keyboard repeats,
not mouse button repeats. I can think of one good application
for mouse button repeats: holding down scrollbar arrows
to scroll a scrollpane or other viewport.

JW

Poynter wrote:>

I noticed that SDL_PollEvent(&event) doesn’t seem to register an event if I
keep a key debounced (pushed down). Is there a good way to take care of
this? What I want to be able to do is continually read the event if the
user holds down a key, rather than just having him tap it repeatedly to get
an event signaled. Thanks… Right now I’m doing this:

SDL_Event event;
while ( SDL_PollEvent(&event) )
{
if ( event.type == SDL_QUIT )
{
exit = 1;
}
// exit
if ( event.key.state == SDL_PRESSED )
{
if ( event.key.keysym.sym == SDLK_ESCAPE )
{
exit = 1;
}
// move the model
if (event.key.keysym.sym == SDLK_r)
{
model1.translate(0, 0.1, 0);
}
}

-TP


// John Watson
// Software Engineer – STScI Archive Team

Use this function:

extern void SDL_EnableKeyRepeat(int delay, int interval);

Of course, I think this only applies to keyboard repeats,
not mouse button repeats. I can think of one good application
for mouse button repeats: holding down scrollbar arrows
to scroll a scrollpane or other viewport.

You can also poll the current keyboard and mouse state using:

SDL_GetKeyState()
and
SDL_GetMouseState()

See ya!
-Sam Lantinga (slouken at devolution.com)

Lead Programmer, Loki Entertainment Software–
“Any sufficiently advanced bug is indistinguishable from a feature”
– Rich Kulawiec

Poynter wrote:

I noticed that SDL_PollEvent(&event) doesn’t seem to register an event if I
keep a key debounced (pushed down). Is there a good way to take care of
this? What I want to be able to do is continually read the event if the
user holds down a key, rather than just having him tap it repeatedly to get
an event signaled. Thanks… Right now I’m doing this:

SDL_Event event;
while ( SDL_PollEvent(&event) )
{
if ( event.type == SDL_QUIT )
{
exit = 1;
}
// exit
if ( event.key.state == SDL_PRESSED )
{
if ( event.key.keysym.sym == SDLK_ESCAPE )
{
exit = 1;
}
// move the model
if (event.key.keysym.sym == SDLK_r)
{
model1.translate(0, 0.1, 0);
}
}

-TP

The natural thing to do would be to store the state yourself, have a variable
stores whether the key of interest is up or down (this could be an array if
you’re interested in many keys). The event handler for that key just sets the
state appropriately. Taking appropriate action on the based on the current
keys pressed can be handled after each event, when no events are currently
queued, or even using a timer. There are obviously other ways you could handle
this, depending on your situation. It seems unnatural for the lack of an
action (in this case the user letting go of a key) to be considered an “event”.

Dana

Poynter wrote:

*** Este es un mail que proviene de Internet.
*** Existe la posibilidad de que el autor no sea quien dice ser, o que el contenido haya sido alterado.
*** No envie informacion sensitiva, dado que su correo puede ser visto y/o modificado por otros.
*** Enviado desde: mail.lokigames.com [63.80.144.66]
*** Sender original: owner-sdl at lokigames.com
*** Receiver original: @Diego_Reyes

I noticed that SDL_PollEvent(&event) doesn’t seem to register an event if I
keep a key debounced (pushed down). Is there a good way to take care of
this? What I want to be able to do is continually read the event if the
user holds down a key, rather than just having him tap it repeatedly to get
an event signaled. Thanks… Right now I’m doing this:

SDL_Event event;
while ( SDL_PollEvent(&event) )
{
if ( event.type == SDL_QUIT )
{
exit = 1;
}
// exit
if ( event.key.state == SDL_PRESSED )
{
if ( event.key.keysym.sym == SDLK_ESCAPE )
{
exit = 1;
}
// move the model
if (event.key.keysym.sym == SDLK_r)
{
model1.translate(0, 0.1, 0);
}
}

-TP

Wouldn’t it be SDL_PRESSED until you get a SDL_RELEASED (or something)
event?–
Diego Reyes
Tecnologia
BBV - Banco Frances
TE: 43464000 int 1211