Add missing VS2012 test projects; update VS2010 and VS2012 solutions; update keybord suite for VS compiler warnings
2 Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
4 This software is provided 'as-is', without any express or implied
5 warranty. In no event will the authors be held liable for any damages
6 arising from the use of this software.
8 Permission is granted to anyone to use this software for any purpose,
9 including commercial applications, and to alter it and redistribute it
13 /* Simple program: Loop, watching keystrokes
14 Note that you need to call SDL_PollEvent() or SDL_WaitEvent() to
15 pump the event loop and catch keystrokes.
24 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
33 print_string(char **text, size_t *maxlen, const char *fmt, ...)
39 len = SDL_vsnprintf(*text, *maxlen, fmt, ap);
42 if ( ((size_t) len) < *maxlen ) {
43 *maxlen -= (size_t) len;
52 print_modifiers(char **text, size_t *maxlen)
55 print_string(text, maxlen, " modifiers:");
56 mod = SDL_GetModState();
58 print_string(text, maxlen, " (none)");
61 if (mod & KMOD_LSHIFT)
62 print_string(text, maxlen, " LSHIFT");
63 if (mod & KMOD_RSHIFT)
64 print_string(text, maxlen, " RSHIFT");
66 print_string(text, maxlen, " LCTRL");
68 print_string(text, maxlen, " RCTRL");
70 print_string(text, maxlen, " LALT");
72 print_string(text, maxlen, " RALT");
74 print_string(text, maxlen, " LGUI");
76 print_string(text, maxlen, " RGUI");
78 print_string(text, maxlen, " NUM");
80 print_string(text, maxlen, " CAPS");
82 print_string(text, maxlen, " MODE");
86 PrintKey(SDL_Keysym * sym, SDL_bool pressed, SDL_bool repeat)
93 left = sizeof(message);
95 /* Print the keycode, name and state */
97 print_string(&spot, &left,
98 "Key %s: scancode %d = %s, keycode 0x%08X = %s ",
99 pressed ? "pressed " : "released",
101 SDL_GetScancodeName(sym->scancode),
102 sym->sym, SDL_GetKeyName(sym->sym));
104 print_string(&spot, &left,
105 "Unknown Key (scancode %d = %s) %s ",
107 SDL_GetScancodeName(sym->scancode),
108 pressed ? "pressed " : "released");
111 /* Print the translated character, if one exists */
113 /* Is it a control-character? */
114 if (sym->unicode < ' ') {
115 print_string(&spot, &left, " (^%c)", sym->unicode + '@');
118 print_string(&spot, &left, " (%c)", sym->unicode);
120 /* This is a Latin-1 program, so only show 8-bits */
121 if (!(sym->unicode & 0xFF00))
122 print_string(&spot, &left, " (%c)", sym->unicode);
124 print_string(&spot, &left, " (0x%X)", sym->unicode);
128 print_modifiers(&spot, &left);
130 print_string(&spot, &left, " (repeat)");
132 SDL_Log("%s\n", message);
136 PrintText(char *text)
138 SDL_Log("Text: %s\n", text);
142 main(int argc, char *argv[])
149 if (SDL_Init(SDL_INIT_VIDEO) < 0) {
150 fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
154 /* Set 640x480 video mode */
155 window = SDL_CreateWindow("CheckKeys Test",
156 SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
159 fprintf(stderr, "Couldn't create 640x480 window: %s\n",
165 /* Creating the context creates the view, which we need to show keyboard */
166 SDL_GL_CreateContext(window);
169 SDL_StartTextInput();
171 /* Watch keystrokes */
174 /* Check for events */
175 SDL_WaitEvent(&event);
176 switch (event.type) {
179 PrintKey(&event.key.keysym, event.key.state, event.key.repeat);
182 PrintText(event.text.text);
184 case SDL_MOUSEBUTTONDOWN:
185 /* Any button press quits the app... */
198 /* vi: set ts=4 sw=4 expandtab: */