Pregunta

Estoy completamente perplejo en cuanto a por qué este código no obtiene ningún evento de pulsación de teclas SDL. Los otros eventos SDL (eliminados por claridad) funcionan bien. No funciona en mis máquinas XP o Vista. Sin errores de compilación / enlace, simplemente nunca reciba un evento de desactivación de claves.

#include "SDL/SDL.h"
// Yes SDL.lib and SDLmain.lib are linked

Uint32 TimeLeft(void)
{
    static Uint32 next_time = 0;
    Uint32 now;
    now = SDL_GetTicks();
    if ( next_time <= now ) {
        next_time = now + tickInterval;
        return 0;
    }
    return(next_time-now);
}

int main( int argc, char **argv )
{
    if( -1 == SDL_Init( SDL_INIT_EVERYTHING ) )
    {
        cerr << "Error: SDL_Init failed" << endl;
        return -1;
    }

    SDL_Event event;

    bool quit = false;

    while( !quit )
    {
        while( SDL_PollEvent( &event ) )
        {
            switch( event.type )
            {
            case SDL_KEYDOWN:
                switch( event.key.keysym.sym )
                {
                case SDLK_ESCAPE:
                case SDLK_q:
                    quit = true;
                    break;
                default:
                    break;
                }
                break;
            case SDL_JOYAXISMOTION:
                // stuff removed
                break;
            case SDL_QUIT:
                quit = true;
                break;
            default:
                break;
            }
        }
        SDL_Delay( TimeLeft() );
    }

    SDL_Quit();

    return 0;
}
¿Fue útil?

Solución

Deberá crear una ventana con SDL_SetVideoMode para obtener el mouse y el teclado eventos.

No creo que tengas suerte al intentar SDL_WM_GrabInput el mouse y teclado sin ventana. También puede generar alertas de seguridad la primera vez en máquinas modernas de Windows.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top