コード例 #1
0
ファイル: rkp_2_key.c プロジェクト: MayKeoN/rkp
int			key_input(void)
{
  SDL_Event event;



  /* Poll for events. SDL_PollEvent() returns 0 when there are no  */
  /* more events on the event queue, our while loop will exit when */
  /* that occurs.                                                  */
  while (SDL_PollEvent(&event))
  {
	// SDL_EnableUNICODE(1);
    /* We are only worried about SDL_KEYDOWN and SDL_KEYUP events */
    switch (event.type)
    {
      case SDL_KEYDOWN:
        printf( "Key press detected\n" );
        PrintKeyInfo( &event.key );
     	if (event.key.keysym.sym == SDLK_SPACE)
	        return (1);
	    else if (event.key.keysym.sym == SDLK_ESCAPE)
	    {
	    	SDL_Quit();
	    	exit(0);
	    }

      case SDL_KEYUP:
        // printf( "Key release detected\n" );
        // PrintKeyInfo( &event.key );
        break;

      case SDL_QUIT:
    	  // PrintKeyInfo( &event.key );
	      SDL_Quit();
	      exit(0);
	  break;

      default:
        break;
    }

  }
  return (0);
}
コード例 #2
0
ファイル: Keylistener.c プロジェクト: PurdueSIGAI/IRIS
int main( int argc, char *argv[] ){
    int x,y;
    int quit = 0;
    init_cursor();
    bClick = 0;
    if( SDL_Init( SDL_INIT_VIDEO ) < 0){
        exit( -1 );
    }

    if( !SDL_SetVideoMode( 320, 200, 0, 0 ) ){
        SDL_Quit();
        exit( -1 );
    }

    time(&last_mouse);
    SDL_EnableUNICODE( 1 );
    set_cursor(x, y);
    while( !quit ){
        check_time();
        while( SDL_PollEvent( &event ) ){
            switch( event.type ){
                case SDL_KEYDOWN:
                    PrintKeyInfo( &event.key );
                    break;
                case SDL_QUIT:
                    quit = 1;
                    break;
                default:
                    checkHold();
                    break;
            }
        }
        sleep(.05);

    }
    SDL_Quit();
    exit( 0 );
}