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 static void print_modifiers(void)
16 printf(" modifiers:");
17 mod = SDL_GetModState();
46 static void PrintKey(SDL_keysym *sym, int pressed)
48 /* Print the keycode, name and state */
50 printf("Key %s: %d-%s ", pressed ? "pressed" : "released",
51 sym->sym, SDL_GetKeyName(sym->sym));
53 printf("Unknown Key (scancode = %d) %s ", sym->scancode,
54 pressed ? "pressed" : "released");
57 /* Print the translated character, if one exists */
59 /* Is it a control-character? */
60 if ( sym->unicode < ' ' ) {
61 printf(" (^%c)", sym->unicode+'@');
64 printf(" (%c)", sym->unicode);
66 /* This is a Latin-1 program, so only show 8-bits */
67 if ( !(sym->unicode & 0xFF00) )
68 printf(" (%c)", sym->unicode);
76 int main(int argc, char *argv[])
83 if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
84 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
89 videoflags = SDL_SWSURFACE;
90 if ( strcmp(argv[1], "-fullscreen") == 0 ) {
91 videoflags |= SDL_FULLSCREEN;
94 /* Set 640x480 video mode */
95 if ( SDL_SetVideoMode(640, 480, 0, videoflags) == NULL ) {
96 fprintf(stderr, "Couldn't set 640x480 video mode: %s\n",
101 /* Enable UNICODE translation for keyboard input */
102 SDL_EnableUNICODE(1);
104 /* Enable auto repeat for keyboard input */
105 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY,
106 SDL_DEFAULT_REPEAT_INTERVAL);
108 /* Watch keystrokes */
111 /* Check for events */
112 SDL_WaitEvent(&event);
113 switch (event.type) {
115 PrintKey(&event.key.keysym, 1);
118 PrintKey(&event.key.keysym, 0);
120 case SDL_MOUSEBUTTONDOWN:
121 /* Any button press quits the app... */