2 /* Simple program: Loop, watching keystrokes
3 Note that you need to call SDL_PollEvent() or SDL_WaitEvent() to
4 pump the event loop and catch keystrokes.
13 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
14 static void quit(int rc)
20 static void print_modifiers(void)
23 printf(" modifiers:");
24 mod = SDL_GetModState();
53 static void PrintKey(SDL_keysym *sym, int pressed)
55 /* Print the keycode, name and state */
57 printf("Key %s: %d-%s ", pressed ? "pressed" : "released",
58 sym->sym, SDL_GetKeyName(sym->sym));
60 printf("Unknown Key (scancode = %d) %s ", sym->scancode,
61 pressed ? "pressed" : "released");
64 /* Print the translated character, if one exists */
66 /* Is it a control-character? */
67 if ( sym->unicode < ' ' ) {
68 printf(" (^%c)", sym->unicode+'@');
71 printf(" (%c)", sym->unicode);
73 /* This is a Latin-1 program, so only show 8-bits */
74 if ( !(sym->unicode & 0xFF00) )
75 printf(" (%c)", sym->unicode);
77 printf(" (0x%X)", sym->unicode);
85 int main(int argc, char *argv[])
92 if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
93 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
97 videoflags = SDL_SWSURFACE;
100 if ( argv[argc] && !strcmp(argv[argc], "-fullscreen") ) {
101 videoflags |= SDL_FULLSCREEN;
103 fprintf(stderr, "Usage: %s [-fullscreen]\n", argv[0]);
108 /* Set 640x480 video mode */
109 if ( SDL_SetVideoMode(640, 480, 0, videoflags) == NULL ) {
110 fprintf(stderr, "Couldn't set 640x480 video mode: %s\n",
115 /* Enable UNICODE translation for keyboard input */
116 SDL_EnableUNICODE(1);
118 /* Enable auto repeat for keyboard input */
119 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY,
120 SDL_DEFAULT_REPEAT_INTERVAL);
122 /* Watch keystrokes */
125 /* Check for events */
126 SDL_WaitEvent(&event);
127 switch (event.type) {
129 PrintKey(&event.key.keysym, 1);
132 PrintKey(&event.key.keysym, 0);
134 case SDL_MOUSEBUTTONDOWN:
135 /* Any button press quits the app... */