[SDL] Re: SDL Input (basic question)

Petri Latvala adrinael at nuclearzone.org
Thu Jul 25 22:38:00 PDT 2002

On Thu, Jul 25, 2002 at 09:14:53PM -0700, Chris Thielen wrote:
> I have the following code segment in a function, and that function is
> called often. I have the value of SDLK_LEFT stored as an SDLKey in the
> "keys" structure. As a test, whenever the left arrow key is pressed, I
> have it print "rotating left!". This is constantly being called in a
> loop, yet if I press and hold the left arrow key down, it only prints
> "rotating left!" once. What's wrong below? (I'd like it to constantly
> print "rotating left!")

KEYDOWN event is basically "a button went down". And in your case, the
button goes down once, and thus generates only one event. One solution
would be to update a flag (key_is_down) on KEYDOWN _and_ on
KEYUP. Another would be to SDL_PumpEvents on regular intervals and
checking the keys with SDL_GetKeyState. Others, how does enabling key
repeat work here?

Petri Latvala
adrinael at nuclearzone.org

More information about the SDL mailing list