author | Philipp Wiesemann <philipp.wiesemann@arcor.de> |
Wed, 25 Nov 2015 21:39:28 +0100 | |
changeset 9922 | b066d5fd5fa7 |
parent 9667 | e55dad50b3ae |
child 9998 | f67cf37e9cd4 |
permissions | -rw-r--r-- |
5535
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5461
diff
changeset
|
1 |
/* |
9619
b94b6d0bff0f
Updated the copyright year to 2015
Sam Lantinga <slouken@libsdl.org>
parents:
9607
diff
changeset
|
2 |
Copyright (C) 1997-2015 Sam Lantinga <slouken@libsdl.org> |
5535
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5461
diff
changeset
|
3 |
|
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5461
diff
changeset
|
4 |
This software is provided 'as-is', without any express or implied |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5461
diff
changeset
|
5 |
warranty. In no event will the authors be held liable for any damages |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5461
diff
changeset
|
6 |
arising from the use of this software. |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5461
diff
changeset
|
7 |
|
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5461
diff
changeset
|
8 |
Permission is granted to anyone to use this software for any purpose, |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5461
diff
changeset
|
9 |
including commercial applications, and to alter it and redistribute it |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5461
diff
changeset
|
10 |
freely. |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5461
diff
changeset
|
11 |
*/ |
0 | 12 |
|
13 |
/* Simple program: Loop, watching keystrokes |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6922
diff
changeset
|
14 |
Note that you need to call SDL_PollEvent() or SDL_WaitEvent() to |
0 | 15 |
pump the event loop and catch keystrokes. |
16 |
*/ |
|
17 |
||
18 |
#include <stdio.h> |
|
19 |
#include <stdlib.h> |
|
20 |
#include <string.h> |
|
21 |
||
9278
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset
|
22 |
#ifdef __EMSCRIPTEN__ |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset
|
23 |
#include <emscripten/emscripten.h> |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset
|
24 |
#endif |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset
|
25 |
|
0 | 26 |
#include "SDL.h" |
27 |
||
9278
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset
|
28 |
int done; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset
|
29 |
|
1151
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
493
diff
changeset
|
30 |
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1253
diff
changeset
|
31 |
static void |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1253
diff
changeset
|
32 |
quit(int rc) |
1151
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
493
diff
changeset
|
33 |
{ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1253
diff
changeset
|
34 |
SDL_Quit(); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1253
diff
changeset
|
35 |
exit(rc); |
1151
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
493
diff
changeset
|
36 |
} |
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
493
diff
changeset
|
37 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1253
diff
changeset
|
38 |
static void |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
39 |
print_string(char **text, size_t *maxlen, const char *fmt, ...) |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
40 |
{ |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
41 |
int len; |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
42 |
va_list ap; |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
43 |
|
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
44 |
va_start(ap, fmt); |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
45 |
len = SDL_vsnprintf(*text, *maxlen, fmt, ap); |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
46 |
if (len > 0) { |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
47 |
*text += len; |
5879
cdb371a9b4a1
Fixed a compiler warning on Visual Studio.
Ryan C. Gordon <icculus@icculus.org>
parents:
5535
diff
changeset
|
48 |
if ( ((size_t) len) < *maxlen ) { |
cdb371a9b4a1
Fixed a compiler warning on Visual Studio.
Ryan C. Gordon <icculus@icculus.org>
parents:
5535
diff
changeset
|
49 |
*maxlen -= (size_t) len; |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
50 |
} else { |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
51 |
*maxlen = 0; |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
52 |
} |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
53 |
} |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
54 |
va_end(ap); |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
55 |
} |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
56 |
|
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
57 |
static void |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
58 |
print_modifiers(char **text, size_t *maxlen) |
0 | 59 |
{ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1253
diff
changeset
|
60 |
int mod; |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
61 |
print_string(text, maxlen, " modifiers:"); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1253
diff
changeset
|
62 |
mod = SDL_GetModState(); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1253
diff
changeset
|
63 |
if (!mod) { |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
64 |
print_string(text, maxlen, " (none)"); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1253
diff
changeset
|
65 |
return; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1253
diff
changeset
|
66 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1253
diff
changeset
|
67 |
if (mod & KMOD_LSHIFT) |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
68 |
print_string(text, maxlen, " LSHIFT"); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1253
diff
changeset
|
69 |
if (mod & KMOD_RSHIFT) |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
70 |
print_string(text, maxlen, " RSHIFT"); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1253
diff
changeset
|
71 |
if (mod & KMOD_LCTRL) |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
72 |
print_string(text, maxlen, " LCTRL"); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1253
diff
changeset
|
73 |
if (mod & KMOD_RCTRL) |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
74 |
print_string(text, maxlen, " RCTRL"); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1253
diff
changeset
|
75 |
if (mod & KMOD_LALT) |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
76 |
print_string(text, maxlen, " LALT"); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1253
diff
changeset
|
77 |
if (mod & KMOD_RALT) |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
78 |
print_string(text, maxlen, " RALT"); |
2303
d87417504c75
First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents:
2300
diff
changeset
|
79 |
if (mod & KMOD_LGUI) |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
80 |
print_string(text, maxlen, " LGUI"); |
2303
d87417504c75
First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents:
2300
diff
changeset
|
81 |
if (mod & KMOD_RGUI) |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
82 |
print_string(text, maxlen, " RGUI"); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1253
diff
changeset
|
83 |
if (mod & KMOD_NUM) |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
84 |
print_string(text, maxlen, " NUM"); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1253
diff
changeset
|
85 |
if (mod & KMOD_CAPS) |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
86 |
print_string(text, maxlen, " CAPS"); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1253
diff
changeset
|
87 |
if (mod & KMOD_MODE) |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
88 |
print_string(text, maxlen, " MODE"); |
0 | 89 |
} |
90 |
||
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1253
diff
changeset
|
91 |
static void |
9667
e55dad50b3ae
Fixed X11 build, added code to print initial modifiers to checkkeys
Sam Lantinga <slouken@libsdl.org>
parents:
9619
diff
changeset
|
92 |
PrintModifierState() |
e55dad50b3ae
Fixed X11 build, added code to print initial modifiers to checkkeys
Sam Lantinga <slouken@libsdl.org>
parents:
9619
diff
changeset
|
93 |
{ |
e55dad50b3ae
Fixed X11 build, added code to print initial modifiers to checkkeys
Sam Lantinga <slouken@libsdl.org>
parents:
9619
diff
changeset
|
94 |
char message[512]; |
e55dad50b3ae
Fixed X11 build, added code to print initial modifiers to checkkeys
Sam Lantinga <slouken@libsdl.org>
parents:
9619
diff
changeset
|
95 |
char *spot; |
e55dad50b3ae
Fixed X11 build, added code to print initial modifiers to checkkeys
Sam Lantinga <slouken@libsdl.org>
parents:
9619
diff
changeset
|
96 |
size_t left; |
e55dad50b3ae
Fixed X11 build, added code to print initial modifiers to checkkeys
Sam Lantinga <slouken@libsdl.org>
parents:
9619
diff
changeset
|
97 |
|
e55dad50b3ae
Fixed X11 build, added code to print initial modifiers to checkkeys
Sam Lantinga <slouken@libsdl.org>
parents:
9619
diff
changeset
|
98 |
spot = message; |
e55dad50b3ae
Fixed X11 build, added code to print initial modifiers to checkkeys
Sam Lantinga <slouken@libsdl.org>
parents:
9619
diff
changeset
|
99 |
left = sizeof(message); |
e55dad50b3ae
Fixed X11 build, added code to print initial modifiers to checkkeys
Sam Lantinga <slouken@libsdl.org>
parents:
9619
diff
changeset
|
100 |
|
e55dad50b3ae
Fixed X11 build, added code to print initial modifiers to checkkeys
Sam Lantinga <slouken@libsdl.org>
parents:
9619
diff
changeset
|
101 |
print_modifiers(&spot, &left); |
e55dad50b3ae
Fixed X11 build, added code to print initial modifiers to checkkeys
Sam Lantinga <slouken@libsdl.org>
parents:
9619
diff
changeset
|
102 |
SDL_Log("Initial state:%s\n", message); |
e55dad50b3ae
Fixed X11 build, added code to print initial modifiers to checkkeys
Sam Lantinga <slouken@libsdl.org>
parents:
9619
diff
changeset
|
103 |
} |
e55dad50b3ae
Fixed X11 build, added code to print initial modifiers to checkkeys
Sam Lantinga <slouken@libsdl.org>
parents:
9619
diff
changeset
|
104 |
|
e55dad50b3ae
Fixed X11 build, added code to print initial modifiers to checkkeys
Sam Lantinga <slouken@libsdl.org>
parents:
9619
diff
changeset
|
105 |
static void |
5218
572a73d71b5f
Sheena pointed out that "scancode" and "keysym" are single words and shouldn't be camel-cased.
Sam Lantinga <slouken@libsdl.org>
parents:
5081
diff
changeset
|
106 |
PrintKey(SDL_Keysym * sym, SDL_bool pressed, SDL_bool repeat) |
0 | 107 |
{ |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
108 |
char message[512]; |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
109 |
char *spot; |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
110 |
size_t left; |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
111 |
|
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
112 |
spot = message; |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
113 |
left = sizeof(message); |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
114 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1253
diff
changeset
|
115 |
/* Print the keycode, name and state */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1253
diff
changeset
|
116 |
if (sym->sym) { |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
117 |
print_string(&spot, &left, |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
118 |
"Key %s: scancode %d = %s, keycode 0x%08X = %s ", |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
119 |
pressed ? "pressed " : "released", |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
120 |
sym->scancode, |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
121 |
SDL_GetScancodeName(sym->scancode), |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
122 |
sym->sym, SDL_GetKeyName(sym->sym)); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1253
diff
changeset
|
123 |
} else { |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
124 |
print_string(&spot, &left, |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
125 |
"Unknown Key (scancode %d = %s) %s ", |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
126 |
sym->scancode, |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
127 |
SDL_GetScancodeName(sym->scancode), |
6922 | 128 |
pressed ? "pressed " : "released"); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1253
diff
changeset
|
129 |
} |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
130 |
print_modifiers(&spot, &left); |
4560
95352c671a6e
Added support for keyboard repeat (only tested on Windows so far)
Sam Lantinga <slouken@libsdl.org>
parents:
2315
diff
changeset
|
131 |
if (repeat) { |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
132 |
print_string(&spot, &left, " (repeat)"); |
4560
95352c671a6e
Added support for keyboard repeat (only tested on Windows so far)
Sam Lantinga <slouken@libsdl.org>
parents:
2315
diff
changeset
|
133 |
} |
6922 | 134 |
SDL_Log("%s\n", message); |
0 | 135 |
} |
136 |
||
2300
c97ad1abe05b
Minimal implementation of textinput events for x11. It only works for latin-1.
Bob Pendleton <bob@pendleton.com>
parents:
2295
diff
changeset
|
137 |
static void |
9581
4da24acfbd90
checkkeys: report SDL_TEXTEDITING events.
Ryan C. Gordon <icculus@icculus.org>
parents:
9580
diff
changeset
|
138 |
PrintText(char *eventtype, char *text) |
2300
c97ad1abe05b
Minimal implementation of textinput events for x11. It only works for latin-1.
Bob Pendleton <bob@pendleton.com>
parents:
2295
diff
changeset
|
139 |
{ |
7639
9406b7dd2f2d
Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
7517
diff
changeset
|
140 |
char *spot, expanded[1024]; |
7317
37b77749523b
Better text printing for UTF-8 characters
Sam Lantinga <slouken@libsdl.org>
parents:
7312
diff
changeset
|
141 |
|
37b77749523b
Better text printing for UTF-8 characters
Sam Lantinga <slouken@libsdl.org>
parents:
7312
diff
changeset
|
142 |
expanded[0] = '\0'; |
37b77749523b
Better text printing for UTF-8 characters
Sam Lantinga <slouken@libsdl.org>
parents:
7312
diff
changeset
|
143 |
for ( spot = text; *spot; ++spot ) |
37b77749523b
Better text printing for UTF-8 characters
Sam Lantinga <slouken@libsdl.org>
parents:
7312
diff
changeset
|
144 |
{ |
37b77749523b
Better text printing for UTF-8 characters
Sam Lantinga <slouken@libsdl.org>
parents:
7312
diff
changeset
|
145 |
size_t length = SDL_strlen(expanded); |
7639
9406b7dd2f2d
Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
7517
diff
changeset
|
146 |
SDL_snprintf(expanded + length, sizeof(expanded) - length, "\\x%.2x", (unsigned char)*spot); |
7317
37b77749523b
Better text printing for UTF-8 characters
Sam Lantinga <slouken@libsdl.org>
parents:
7312
diff
changeset
|
147 |
} |
9581
4da24acfbd90
checkkeys: report SDL_TEXTEDITING events.
Ryan C. Gordon <icculus@icculus.org>
parents:
9580
diff
changeset
|
148 |
SDL_Log("%s Text (%s): \"%s%s\"\n", eventtype, expanded, *text == '"' ? "\\" : "", text); |
2300
c97ad1abe05b
Minimal implementation of textinput events for x11. It only works for latin-1.
Bob Pendleton <bob@pendleton.com>
parents:
2295
diff
changeset
|
149 |
} |
c97ad1abe05b
Minimal implementation of textinput events for x11. It only works for latin-1.
Bob Pendleton <bob@pendleton.com>
parents:
2295
diff
changeset
|
150 |
|
9278
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset
|
151 |
void |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset
|
152 |
loop() |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset
|
153 |
{ |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset
|
154 |
SDL_Event event; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset
|
155 |
/* Check for events */ |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset
|
156 |
/*SDL_WaitEvent(&event); emscripten does not like waiting*/ |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset
|
157 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset
|
158 |
while (SDL_PollEvent(&event)) { |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset
|
159 |
switch (event.type) { |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset
|
160 |
case SDL_KEYDOWN: |
9580
d37ef6990bf9
checkkeys: Readded the KEYUP event test.
Ryan C. Gordon <icculus@icculus.org>
parents:
9278
diff
changeset
|
161 |
case SDL_KEYUP: |
9922
b066d5fd5fa7
Replaced tabs with spaces in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9667
diff
changeset
|
162 |
PrintKey(&event.key.keysym, (event.key.state == SDL_PRESSED) ? SDL_TRUE : SDL_FALSE, (event.key.repeat) ? SDL_TRUE : SDL_FALSE); |
9278
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset
|
163 |
break; |
9581
4da24acfbd90
checkkeys: report SDL_TEXTEDITING events.
Ryan C. Gordon <icculus@icculus.org>
parents:
9580
diff
changeset
|
164 |
case SDL_TEXTEDITING: |
4da24acfbd90
checkkeys: report SDL_TEXTEDITING events.
Ryan C. Gordon <icculus@icculus.org>
parents:
9580
diff
changeset
|
165 |
PrintText("EDIT", event.text.text); |
4da24acfbd90
checkkeys: report SDL_TEXTEDITING events.
Ryan C. Gordon <icculus@icculus.org>
parents:
9580
diff
changeset
|
166 |
break; |
9278
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset
|
167 |
case SDL_TEXTINPUT: |
9581
4da24acfbd90
checkkeys: report SDL_TEXTEDITING events.
Ryan C. Gordon <icculus@icculus.org>
parents:
9580
diff
changeset
|
168 |
PrintText("INPUT", event.text.text); |
9278
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset
|
169 |
break; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset
|
170 |
case SDL_MOUSEBUTTONDOWN: |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset
|
171 |
/* Any button press quits the app... */ |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset
|
172 |
case SDL_QUIT: |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset
|
173 |
done = 1; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset
|
174 |
break; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset
|
175 |
default: |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset
|
176 |
break; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset
|
177 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset
|
178 |
} |
9607
7746ab058d12
Added missing loop cancel for Emscripten in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9581
diff
changeset
|
179 |
#ifdef __EMSCRIPTEN__ |
7746ab058d12
Added missing loop cancel for Emscripten in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9581
diff
changeset
|
180 |
if (done) { |
7746ab058d12
Added missing loop cancel for Emscripten in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9581
diff
changeset
|
181 |
emscripten_cancel_main_loop(); |
7746ab058d12
Added missing loop cancel for Emscripten in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9581
diff
changeset
|
182 |
} |
7746ab058d12
Added missing loop cancel for Emscripten in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9581
diff
changeset
|
183 |
#endif |
9278
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset
|
184 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset
|
185 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1253
diff
changeset
|
186 |
int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1253
diff
changeset
|
187 |
main(int argc, char *argv[]) |
0 | 188 |
{ |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
189 |
SDL_Window *window; |
9922
b066d5fd5fa7
Replaced tabs with spaces in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9667
diff
changeset
|
190 |
|
b066d5fd5fa7
Replaced tabs with spaces in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9667
diff
changeset
|
191 |
/* Enable standard application logging */ |
b066d5fd5fa7
Replaced tabs with spaces in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9667
diff
changeset
|
192 |
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); |
0 | 193 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1253
diff
changeset
|
194 |
/* Initialize SDL */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1253
diff
changeset
|
195 |
if (SDL_Init(SDL_INIT_VIDEO) < 0) { |
9922
b066d5fd5fa7
Replaced tabs with spaces in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9667
diff
changeset
|
196 |
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1253
diff
changeset
|
197 |
return (1); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1253
diff
changeset
|
198 |
} |
0 | 199 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1253
diff
changeset
|
200 |
/* Set 640x480 video mode */ |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
201 |
window = SDL_CreateWindow("CheckKeys Test", |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
202 |
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
203 |
640, 480, 0); |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
204 |
if (!window) { |
7639
9406b7dd2f2d
Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
7517
diff
changeset
|
205 |
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create 640x480 window: %s\n", |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1253
diff
changeset
|
206 |
SDL_GetError()); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1253
diff
changeset
|
207 |
quit(2); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1253
diff
changeset
|
208 |
} |
0 | 209 |
|
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
210 |
#if __IPHONEOS__ |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
211 |
/* Creating the context creates the view, which we need to show keyboard */ |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
212 |
SDL_GL_CreateContext(window); |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
213 |
#endif |
6392
fa7eb111f994
Fixed bug 1564 - SDL has no function to open a screen keyboard on Android.
Sam Lantinga <slouken@libsdl.org>
parents:
5879
diff
changeset
|
214 |
|
6654
2ecfb25be1e2
Synchronized the on-screen keyboard state with whether we are accepting text input.
Sam Lantinga <slouken@libsdl.org>
parents:
6392
diff
changeset
|
215 |
SDL_StartTextInput(); |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
216 |
|
9667
e55dad50b3ae
Fixed X11 build, added code to print initial modifiers to checkkeys
Sam Lantinga <slouken@libsdl.org>
parents:
9619
diff
changeset
|
217 |
/* Print initial modifier state */ |
e55dad50b3ae
Fixed X11 build, added code to print initial modifiers to checkkeys
Sam Lantinga <slouken@libsdl.org>
parents:
9619
diff
changeset
|
218 |
SDL_PumpEvents(); |
e55dad50b3ae
Fixed X11 build, added code to print initial modifiers to checkkeys
Sam Lantinga <slouken@libsdl.org>
parents:
9619
diff
changeset
|
219 |
PrintModifierState(); |
e55dad50b3ae
Fixed X11 build, added code to print initial modifiers to checkkeys
Sam Lantinga <slouken@libsdl.org>
parents:
9619
diff
changeset
|
220 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1253
diff
changeset
|
221 |
/* Watch keystrokes */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1253
diff
changeset
|
222 |
done = 0; |
9278
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset
|
223 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset
|
224 |
#ifdef __EMSCRIPTEN__ |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset
|
225 |
emscripten_set_main_loop(loop, 0, 1); |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset
|
226 |
#else |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1253
diff
changeset
|
227 |
while (!done) { |
9278
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset
|
228 |
loop(); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1253
diff
changeset
|
229 |
} |
9278
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
8149
diff
changeset
|
230 |
#endif |
1151
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
493
diff
changeset
|
231 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1253
diff
changeset
|
232 |
SDL_Quit(); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1253
diff
changeset
|
233 |
return (0); |
0 | 234 |
} |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
235 |
|
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
236 |
/* vi: set ts=4 sw=4 expandtab: */ |