6677

SDL key events test

May 22nd, 2014
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.94 KB | None | 0 0
  1. #include <SDL/SDL.h>
  2. int main(int argc, char* args[]) {
  3.     int running = 1;
  4.     SDL_Event event;
  5.     SDL_Init(SDL_INIT_EVERYTHING);//ALL TEH TINGS
  6.     freopen("CON","w",stdout);//SDL init redirects stdout and stderr to text files
  7.     freopen("CON","w",stderr);//Return them to console where I want them
  8.     SDL_WM_SetCaption("Hello, World!", NULL);//window title
  9.     SDL_SetVideoMode(800, 600, 32, SDL_HWSURFACE);//window size
  10.     while (running) {
  11.         SDL_WaitEvent(&event);
  12.         switch (event.type) {
  13.             case SDL_QUIT:
  14.                 running = 0;
  15.                 break;
  16.             case SDL_KEYDOWN:
  17.                 printf("Key press detected\n");
  18.                 break;
  19.             case SDL_KEYUP:
  20.                 printf("Key release detected\n");
  21.                 break;
  22.             default:
  23.                 break;
  24.         }//some self explanatory stuff
  25.     }
  26.     SDL_Quit();
  27.     return 0;//obligatory return 0
  28. }
Advertisement
Add Comment
Please, Sign In to add comment