[SDL] Re: No key pressed
Bruce @ OpenGL
bruce at opengl.com.br
Wed Feb 4 06:24:20 PST 2004
Thanks James, I will consider the use of static variables. I could have
used them, thnxs again.
[]s
Bruce
James Gregory wrote:
>On Wed, 28 Jan 2004 19:19:52 -0200, Bruce @ OpenGL wrote:
>
>
>
>>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; }
>>
>>
>>
>
>As I understand it, SDL_GetKeyState() probably doesn't work in the way
>that you think it does. You only ever need to call it once, at the
>beginning of your program, and from there on in it will always contain the
>current state of the keyboard (as long as you keep pumping/polling events).
>
>Others have explained how you misunderstand the alternative of dealing
>with key events.
>
>Also, as for not liking global variables - if you're using C++ and not
>C, do you know about static variables? You declare them inside the scope
>of a function, but they save their value between each time the function is
>called.
>
> James
>
>
>
>
>
>_______________________________________________
>SDL mailing list
>SDL at libsdl.org
>http://www.libsdl.org/mailman/listinfo/sdl
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20040204/644402c6/attachment.htm>
More information about the SDL
mailing list