First pass of new SDL scancode concept for X11.
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. */
25 printf(" modifiers:");
26 mod = SDL_GetModState();
31 if (mod & KMOD_LSHIFT)
33 if (mod & KMOD_RSHIFT)
56 PrintKey(SDL_keysym * sym, int pressed)
58 /* Print the keycode, name and state */
60 printf("Key %s: scancode 0x%04X = %s, keycode 0x%08X = %s ",
61 pressed ? "pressed " : "released",
63 SDL_GetScancodeName(sym->scancode),
64 sym->sym, SDL_GetKeyName(sym->sym));
66 printf("Unknown Key (scancode = 0x%04X) %s ",
67 sym->scancode, pressed ? "pressed" : "released");
70 /* Print the translated character, if one exists */
72 /* Is it a control-character? */
73 if (sym->unicode < ' ') {
74 printf(" (^%c)", sym->unicode + '@');
77 printf(" (%c)", sym->unicode);
79 /* This is a Latin-1 program, so only show 8-bits */
80 if (!(sym->unicode & 0xFF00))
81 printf(" (%c)", sym->unicode);
83 printf(" (0x%X)", sym->unicode);
94 printf("Text: %s\n", text);
98 main(int argc, char *argv[])
105 if (SDL_Init(SDL_INIT_VIDEO) < 0) {
106 fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
110 videoflags = SDL_SWSURFACE;
113 if (argv[argc] && !strcmp(argv[argc], "-fullscreen")) {
114 videoflags |= SDL_FULLSCREEN;
116 fprintf(stderr, "Usage: %s [-fullscreen]\n", argv[0]);
121 /* Set 640x480 video mode */
122 if (SDL_SetVideoMode(640, 480, 0, videoflags) == NULL) {
123 fprintf(stderr, "Couldn't set 640x480 video mode: %s\n",
128 /* Watch keystrokes */
131 /* Check for events */
132 SDL_WaitEvent(&event);
133 switch (event.type) {
135 PrintKey(&event.key.keysym, 1);
138 PrintKey(&event.key.keysym, 0);
141 PrintText(event.text.text);
143 case SDL_MOUSEBUTTONDOWN:
144 /* Any button press quits the app... */