comparison test/checkkeys.c @ 1662:782fd950bd46 SDL-1.3

Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API. WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid. The code is now run through a consistent indent format: indent -i4 -nut -nsc -br -ce The headers are being converted to automatically generate doxygen documentation.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 28 May 2006 13:04:16 +0000
parents 7c7ddaf195bf
children 4da1ee79c9af
comparison
equal deleted inserted replaced
1661:281d3f4870e5 1662:782fd950bd46
9 #include <string.h> 9 #include <string.h>
10 10
11 #include "SDL.h" 11 #include "SDL.h"
12 12
13 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ 13 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
14 static void quit(int rc) 14 static void
15 quit (int rc)
15 { 16 {
16 SDL_Quit(); 17 SDL_Quit ();
17 exit(rc); 18 exit (rc);
18 } 19 }
19 20
20 static void print_modifiers(void) 21 static void
22 print_modifiers (void)
21 { 23 {
22 int mod; 24 int mod;
23 printf(" modifiers:"); 25 printf (" modifiers:");
24 mod = SDL_GetModState(); 26 mod = SDL_GetModState ();
25 if(!mod) { 27 if (!mod) {
26 printf(" (none)"); 28 printf (" (none)");
27 return; 29 return;
28 } 30 }
29 if(mod & KMOD_LSHIFT) 31 if (mod & KMOD_LSHIFT)
30 printf(" LSHIFT"); 32 printf (" LSHIFT");
31 if(mod & KMOD_RSHIFT) 33 if (mod & KMOD_RSHIFT)
32 printf(" RSHIFT"); 34 printf (" RSHIFT");
33 if(mod & KMOD_LCTRL) 35 if (mod & KMOD_LCTRL)
34 printf(" LCTRL"); 36 printf (" LCTRL");
35 if(mod & KMOD_RCTRL) 37 if (mod & KMOD_RCTRL)
36 printf(" RCTRL"); 38 printf (" RCTRL");
37 if(mod & KMOD_LALT) 39 if (mod & KMOD_LALT)
38 printf(" LALT"); 40 printf (" LALT");
39 if(mod & KMOD_RALT) 41 if (mod & KMOD_RALT)
40 printf(" RALT"); 42 printf (" RALT");
41 if(mod & KMOD_LMETA) 43 if (mod & KMOD_LMETA)
42 printf(" LMETA"); 44 printf (" LMETA");
43 if(mod & KMOD_RMETA) 45 if (mod & KMOD_RMETA)
44 printf(" RMETA"); 46 printf (" RMETA");
45 if(mod & KMOD_NUM) 47 if (mod & KMOD_NUM)
46 printf(" NUM"); 48 printf (" NUM");
47 if(mod & KMOD_CAPS) 49 if (mod & KMOD_CAPS)
48 printf(" CAPS"); 50 printf (" CAPS");
49 if(mod & KMOD_MODE) 51 if (mod & KMOD_MODE)
50 printf(" MODE"); 52 printf (" MODE");
51 } 53 }
52 54
53 static void PrintKey(SDL_keysym *sym, int pressed) 55 static void
56 PrintKey (SDL_keysym * sym, int pressed)
54 { 57 {
55 /* Print the keycode, name and state */ 58 /* Print the keycode, name and state */
56 if ( sym->sym ) { 59 if (sym->sym) {
57 printf("Key %s: %d-%s ", pressed ? "pressed" : "released", 60 printf ("Key %s: %d-%s ", pressed ? "pressed" : "released",
58 sym->sym, SDL_GetKeyName(sym->sym)); 61 sym->sym, SDL_GetKeyName (sym->sym));
59 } else { 62 } else {
60 printf("Unknown Key (scancode = %d) %s ", sym->scancode, 63 printf ("Unknown Key (scancode = %d) %s ", sym->scancode,
61 pressed ? "pressed" : "released"); 64 pressed ? "pressed" : "released");
62 } 65 }
63 66
64 /* Print the translated character, if one exists */ 67 /* Print the translated character, if one exists */
65 if ( sym->unicode ) { 68 if (sym->unicode) {
66 /* Is it a control-character? */ 69 /* Is it a control-character? */
67 if ( sym->unicode < ' ' ) { 70 if (sym->unicode < ' ') {
68 printf(" (^%c)", sym->unicode+'@'); 71 printf (" (^%c)", sym->unicode + '@');
69 } else { 72 } else {
70 #ifdef UNICODE 73 #ifdef UNICODE
71 printf(" (%c)", sym->unicode); 74 printf (" (%c)", sym->unicode);
72 #else 75 #else
73 /* This is a Latin-1 program, so only show 8-bits */ 76 /* This is a Latin-1 program, so only show 8-bits */
74 if ( !(sym->unicode & 0xFF00) ) 77 if (!(sym->unicode & 0xFF00))
75 printf(" (%c)", sym->unicode); 78 printf (" (%c)", sym->unicode);
76 else 79 else
77 printf(" (0x%X)", sym->unicode); 80 printf (" (0x%X)", sym->unicode);
78 #endif 81 #endif
79 } 82 }
80 } 83 }
81 print_modifiers(); 84 print_modifiers ();
82 printf("\n"); 85 printf ("\n");
83 } 86 }
84 87
85 int main(int argc, char *argv[]) 88 int
89 main (int argc, char *argv[])
86 { 90 {
87 SDL_Event event; 91 SDL_Event event;
88 int done; 92 int done;
89 Uint32 videoflags; 93 Uint32 videoflags;
90 94
91 /* Initialize SDL */ 95 /* Initialize SDL */
92 if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { 96 if (SDL_Init (SDL_INIT_VIDEO) < 0) {
93 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); 97 fprintf (stderr, "Couldn't initialize SDL: %s\n", SDL_GetError ());
94 return(1); 98 return (1);
95 } 99 }
96 100
97 videoflags = SDL_SWSURFACE; 101 videoflags = SDL_SWSURFACE;
98 while( argc > 1 ) { 102 while (argc > 1) {
99 --argc; 103 --argc;
100 if ( argv[argc] && !strcmp(argv[argc], "-fullscreen") ) { 104 if (argv[argc] && !strcmp (argv[argc], "-fullscreen")) {
101 videoflags |= SDL_FULLSCREEN; 105 videoflags |= SDL_FULLSCREEN;
102 } else { 106 } else {
103 fprintf(stderr, "Usage: %s [-fullscreen]\n", argv[0]); 107 fprintf (stderr, "Usage: %s [-fullscreen]\n", argv[0]);
104 quit(1); 108 quit (1);
105 } 109 }
106 } 110 }
107 111
108 /* Set 640x480 video mode */ 112 /* Set 640x480 video mode */
109 if ( SDL_SetVideoMode(640, 480, 0, videoflags) == NULL ) { 113 if (SDL_SetVideoMode (640, 480, 0, videoflags) == NULL) {
110 fprintf(stderr, "Couldn't set 640x480 video mode: %s\n", 114 fprintf (stderr, "Couldn't set 640x480 video mode: %s\n",
111 SDL_GetError()); 115 SDL_GetError ());
112 quit(2); 116 quit (2);
113 } 117 }
114 118
115 /* Enable UNICODE translation for keyboard input */ 119 /* Enable UNICODE translation for keyboard input */
116 SDL_EnableUNICODE(1); 120 SDL_EnableUNICODE (1);
117 121
118 /* Enable auto repeat for keyboard input */ 122 /* Enable auto repeat for keyboard input */
119 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, 123 SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY,
120 SDL_DEFAULT_REPEAT_INTERVAL); 124 SDL_DEFAULT_REPEAT_INTERVAL);
121 125
122 /* Watch keystrokes */ 126 /* Watch keystrokes */
123 done = 0; 127 done = 0;
124 while ( !done ) { 128 while (!done) {
125 /* Check for events */ 129 /* Check for events */
126 SDL_WaitEvent(&event); 130 SDL_WaitEvent (&event);
127 switch (event.type) { 131 switch (event.type) {
128 case SDL_KEYDOWN: 132 case SDL_KEYDOWN:
129 PrintKey(&event.key.keysym, 1); 133 PrintKey (&event.key.keysym, 1);
130 break; 134 break;
131 case SDL_KEYUP: 135 case SDL_KEYUP:
132 PrintKey(&event.key.keysym, 0); 136 PrintKey (&event.key.keysym, 0);
133 break; 137 break;
134 case SDL_MOUSEBUTTONDOWN: 138 case SDL_MOUSEBUTTONDOWN:
135 /* Any button press quits the app... */ 139 /* Any button press quits the app... */
136 case SDL_QUIT: 140 case SDL_QUIT:
137 done = 1; 141 done = 1;
138 break; 142 break;
139 default: 143 default:
140 break; 144 break;
141 } 145 }
142 } 146 }
143 147
144 SDL_Quit(); 148 SDL_Quit ();
145 return(0); 149 return (0);
146 } 150 }