[SDL] keyboard events

Mikael Eriksson mikael.miffe.eriksson at gmail.com
Wed Sep 21 12:27:19 PDT 2005


Michael Whitman wrote:
> I am a first time SDL user.  I am trying to move a sprite around and 
> notice that when I press a key and DO NOT RELEASE it I seem to get a 
> SDL_KEYDOWN event followed immediately by a SDL_KEYUP event.  Then when 
> I release the key I get another SDL_KEYUP event.
> 
> I am running Fedora Core 3 on a Toshiba laptop?  Is this a OS or 
> keyboard issie?
> 
> Here is the relevant code:
> 
> while (1)
>   {
> 
>     // Poll for events, and handle the ones we care about.
>     SDL_Event event;
>     if (SDL_PollEvent(&event))
>     {
>       std::cout << "event.key.keysym.sym is: " << event.key.keysym.sym 
> << std::endl;
>      
>       switch (event.type)
>       {
>       case SDL_KEYDOWN:
>           std::cout << "KEY PRESSED" << std::endl;
>       
You need a brake here.

>       case SDL_KEYUP:
>           std::cout << "KEY RELEASED" << std::endl;
>       }
>      
>     }
>    
>   }
> 
> The output:
> 
> event.key.keysym.sym is: 100
> KEY PRESSED
> KEY RELEASED
> event.key.keysym.sym is: 100
> KEY RELEASED
> event.key.keysym.sym is: 102
> KEY PRESSED
> KEY RELEASED
> event.key.keysym.sym is: 102
> KEY RELEASED
> 
> 
> Is this normal?  I was hope to move the sprite while the key was pressed 
> down and stop it when the key was released.




More information about the SDL mailing list