[SDL] Re: SDL Input (basic question)

Screwtape screwtape at froup.com
Thu Jul 25 23:34:01 PDT 2002

On Fri, 2002-07-26 at 15:31, Petri Latvala wrote:
> 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?

Unsurprisingly, this is a very common question, and it has been added to
the documentation: 


In short, if you want key repeat, you use the key events to keep track
of key state, and every time through your main loop, do something like:

if (leftIsDown)
	printf("rotating left!\n");

 ___________ ____________________________
| Screwtape | Reply-To: munged on Usenet |________ ______ ____ __ _  _  
| Anyone ever told you you're beautiful? No? Ever wondered why?

More information about the SDL mailing list