comparison test/checkkeys.c @ 1668:4da1ee79c9af SDL-1.3

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