[SDL] No key pressed

Jimmy jimmy at jimmysworld.org
Wed Jan 28 17:14:01 PST 2004


I may be misunderstanding you, but it seems that you only want to update
your game when no keys are currently pressed.  Yes?

Maybe the best thing to do is before you start your game loop,
initialize an int to zero, and scan all the keys incrememting your int
for each key currently pressed.

Then watch for key events, and decrement your counter when you see
KEY_UP, and increment it when you see KEY_DOWN.  That way, when your
counter is 0, you know nothing is pressed.  Non-zero means there is.

On Wed, 2004-01-28 at 17:24, Bruce @ OpenGL wrote:
> No Alan, i need to test anyway.
> Thats why I have an update function in my game that is called if no events
> occurred in that frame, and then it checks a variable, "keys", to see if in
> last frame occurred a key press. I cannot update my game in the KEY_DOWN or
> KEY_UP event. So I made this way. So if no key was pressed, how to know ?
> 
> In my last frame an KEY_UP event occurred and SDL_GetKeyState was called...
> I need to know how what value it returns me if no key was pressed.
> I will test NULL and I do not want to do a array scan like Bill said testing
> each key to see if its value is 0 or 1...
> 
> []s
> Bruce
> 
> 
> -----Original Message-----
> From: sdl-admin at libsdl.org [mailto:sdl-admin at libsdl.org]On Behalf Of
> Alan Wolfe
> Sent: quarta-feira, 28 de janeiro de 2004 19:30
> To: sdl at libsdl.org
> Subject: Re: [SDL] No key pressed
> 
> 
> hey Bruce,
> 
> another way to see what keys are pressed is to watch the key down and key up
> events.
> 
> this could help you figure out if a key was pressed since you last checked
> or not.
> 
> ----- Original Message -----
> From: "Bruce @ OpenGL" <bruce at opengl.com.br>
> To: <sdl at libsdl.org>
> Sent: Wednesday, January 28, 2004 1:19 PM
> Subject: [SDL] No key pressed
> 
> 
> > Hi folks,
> >
> > To see which key was pressed, I use SDL_GetKeyState in this way:
> >
> > Uint8* keys;
> > keys = SDL_GetKeyState(NULL);
> >
> > then I check here:
> >
> > if (keys[SDLK_UP])
> >   { do something; }
> >
> > But and if I want to check if no key was pressed, after a call to
> > SDL_GetKeyState ???
> >
> > Thnxs,
> >
> > Bruce Christopher Barrera
> > ------------------
> > Moderador da lista de discussão OpenGL_Brasil
> > http://br.groups.yahoo.com/group/opengl_brasil/
> > Moderador da seção OpenGL do Fórum do PDJ Brasil
> > http://www.pdj.com.br/forum
> >
> > "Existem 10 tipos de pessoas. As que entendem binario e as que nao
> > entendem..."
> >
> >
> > _______________________________________________
> > SDL mailing list
> > SDL at libsdl.org
> > http://www.libsdl.org/mailman/listinfo/sdl
> 
> 
> _______________________________________________
> SDL mailing list
> SDL at libsdl.org
> http://www.libsdl.org/mailman/listinfo/sdl
> 
> 
> _______________________________________________
> SDL mailing list
> SDL at libsdl.org
> http://www.libsdl.org/mailman/listinfo/sdl





More information about the SDL mailing list