Open xiedidan opened 8 years ago
For input events, two handling methods are available:
if( SDL_PollEvent( &event ) )
{
if( event.type == SDL_KEYDOWN )
{
switch( event.key.keysym.sym )
{
case SDLK_UP: ... break;
case SDLK_DOWN: ... break;
case SDLK_LEFT: ... break;
case SDLK_RIGHT: ... break;
}
}
// if window's close button was clicked
else if( event.type == SDL_QUIT )
{
quit = true;
}
}
This method is straightforward, but it's hard to detect key combination.
Uint8 *keystates = SDL_GetKeyState( NULL );
if( keystates[ SDLK_UP ] )
...
if( keystates[ SDLK_DOWN ] )
...
if( keystates[ SDLK_LEFT ] )
...
if( keystates[ SDLK_RIGHT ] )
...
This is much easier for key combination detection.
handler for mouse and keyboard events