[SDL] Event question

carlos citrouille at wanadoo.fr
Wed Jul 31 02:08:01 PDT 2002


> If I PollEvents (which automatically calls PumpEvents), can I still check
> the status of any key?

You can check key status if you keep them in another variable

see what I explain

SDL_Event ev;
int IsKeyPressed[256]

While(1) //main loop
{
    While(SDL_PollEvents(&ev))
    {
        switch(ev.type)
        {
            case SDL_KEYDOWN:
                IsKeyPressed[ev.key.keysym.sym] = 1;
            case SDL_KEYUP:
                IsKeyPressed[ev.key.keysymsym] = 0;
        }
    }
    /then you can check you keys when tyou want in you main loop
    if(IsAKeyPressed[SDLK_DOWN]==1)
        //trulululu
    if(IsAKeyPressed[SDLK_LEFT]==1)
        //plof-plof
}






More information about the SDL mailing list