SDL doesn't detect Arrow Keys

Posted by Scott on Stack Overflow See other posts from Stack Overflow or by Scott
Published on 2010-04-01T01:43:23Z Indexed on 2010/04/01 2:43 UTC
Read the original article Hit count: 524

Filed under:
|
|

I am working through the SDL tutorials over at http://lazyfoo.net/SDL_tutorials/index.php and I'm stuck on tutorial 8 where I'm working with key presses.

I'm using the following code:

//Our Main application loop
while(!quit){
    if(SDL_PollEvent(&curEvents)){
        if(curEvents.type == SDL_QUIT){
            quit = true;
        }

        //If a key was pressed
        if( curEvents.type == SDL_KEYDOWN )
        {
            //Set the proper message surface
            switch( curEvents.key.keysym.sym )
            {
                case SDLK_UP: 
                    message = upMessage; 
                    break;
                case SDLK_DOWN: 
                    message = downMessage; 
                    break;
                case SDLK_LEFT: 
                    message = leftMessage; 
                    break;
                case SDLK_RIGHT: 
                    message = rightMessage; break;
                default:
                    message = TTF_RenderText_Solid(font, "Unknown Key", textColor); 
                    break; 
            }
        }
    }

    if( message != NULL )
    {
        //Apply the background to the screen
        applySurface( 0, 0, background, screen );

        //Apply the message centered on the screen
        applySurface( ( SCREEN_WIDTH - message->w ) / 2, ( SCREEN_HEIGHT - message->h ) / 2, message, screen );

        //Null the surface pointer
        message = NULL;
    }

    //Update the screen
    if( SDL_Flip( screen ) == -1 )
    {
        return 1;
    }
}

Where works fine, the default case is reached, for everything BUT pressing the arrow keys. I was wondering if someone could spot what I'm doing wrong.

© Stack Overflow or respective owner

Related posts about sdl

Related posts about c++