[SDL] keyboard events

Brian Raiter breadbox at muppetlabs.com
Wed Sep 21 12:07:02 PDT 2005


> 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.

Actually, what's wrong is that you forgot to put a break between your
two case statements.

> switch (event.type)
> {
>   case SDL_KEYDOWN:
>     std::cout << "KEY PRESSED" << std::endl;
> 
>   case SDL_KEYUP:
>     std::cout << "KEY RELEASED" << std::endl;
> }

The SDL_KEYDOWN case is simply falling through to the SDL_KEYUP case.

b




More information about the SDL mailing list