author | Sam Lantinga <slouken@libsdl.org> |
Wed, 09 Mar 2011 17:38:12 -0800 | |
changeset 5461 | 94f742ce580a |
parent 5218 | 572a73d71b5f |
child 5535 | 96594ac5fd1a |
permissions | -rw-r--r-- |
0 | 1 |
|
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. |
|
5 |
*/ |
|
6 |
||
7 |
#include <stdio.h> |
|
8 |
#include <stdlib.h> |
|
9 |
#include <string.h> |
|
10 |
||
11 |
#include "SDL.h" |
|
12 |
||
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
|
13 |
/* 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
|
14 |
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
|
15 |
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
|
16 |
{ |
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
|
17 |
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
|
18 |
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
|
19 |
} |
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
|
20 |
|
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
|
21 |
static void |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
22 |
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
|
23 |
{ |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
24 |
int len; |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
25 |
va_list ap; |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
26 |
|
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
27 |
va_start(ap, fmt); |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
28 |
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
|
29 |
if (len > 0) { |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
30 |
*text += len; |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
31 |
if (len < *maxlen) { |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
32 |
*maxlen -= len; |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
33 |
} else { |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
34 |
*maxlen = 0; |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
35 |
} |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
36 |
} |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
37 |
va_end(ap); |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
38 |
} |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
39 |
|
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
40 |
static void |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
41 |
print_modifiers(char **text, size_t *maxlen) |
0 | 42 |
{ |
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
|
43 |
int mod; |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
44 |
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
|
45 |
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
|
46 |
if (!mod) { |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
47 |
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
|
48 |
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
|
49 |
} |
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
|
50 |
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
|
51 |
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
|
52 |
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
|
53 |
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
|
54 |
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
|
55 |
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
|
56 |
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
|
57 |
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
|
58 |
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
|
59 |
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
|
60 |
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
|
61 |
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
|
62 |
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
|
63 |
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
|
64 |
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
|
65 |
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
|
66 |
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
|
67 |
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
|
68 |
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
|
69 |
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
|
70 |
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
|
71 |
print_string(text, maxlen, " MODE"); |
0 | 72 |
} |
73 |
||
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
|
74 |
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
|
75 |
PrintKey(SDL_Keysym * sym, SDL_bool pressed, SDL_bool repeat) |
0 | 76 |
{ |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
77 |
char message[512]; |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
78 |
char *spot; |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
79 |
size_t left; |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
80 |
|
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
81 |
spot = message; |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
82 |
left = sizeof(message); |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
83 |
|
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
|
84 |
/* 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
|
85 |
if (sym->sym) { |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
86 |
print_string(&spot, &left, |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
87 |
"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
|
88 |
pressed ? "pressed " : "released", |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
89 |
sym->scancode, |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
90 |
SDL_GetScancodeName(sym->scancode), |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
91 |
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
|
92 |
} else { |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
93 |
print_string(&spot, &left, |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
94 |
"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
|
95 |
sym->scancode, |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
96 |
SDL_GetScancodeName(sym->scancode), |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
97 |
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
|
98 |
} |
0 | 99 |
|
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
|
100 |
/* Print the translated character, if one exists */ |
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
|
101 |
if (sym->unicode) { |
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
|
102 |
/* Is it a control-character? */ |
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
|
103 |
if (sym->unicode < ' ') { |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
104 |
print_string(&spot, &left, " (^%c)", sym->unicode + '@'); |
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
|
105 |
} else { |
0 | 106 |
#ifdef UNICODE |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
107 |
print_string(&spot, &left, " (%c)", sym->unicode); |
0 | 108 |
#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
|
109 |
/* This is a Latin-1 program, so only show 8-bits */ |
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
|
110 |
if (!(sym->unicode & 0xFF00)) |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
111 |
print_string(&spot, &left, " (%c)", sym->unicode); |
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
|
112 |
else |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
113 |
print_string(&spot, &left, " (0x%X)", sym->unicode); |
0 | 114 |
#endif |
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 |
} |
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 |
} |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
117 |
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
|
118 |
if (repeat) { |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
119 |
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
|
120 |
} |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
121 |
SDL_Log("%s", message); |
0 | 122 |
} |
123 |
||
2300
c97ad1abe05b
Minimal implementation of textinput events for x11. It only works for latin-1.
Bob Pendleton <bob@pendleton.com>
parents:
2295
diff
changeset
|
124 |
static void |
c97ad1abe05b
Minimal implementation of textinput events for x11. It only works for latin-1.
Bob Pendleton <bob@pendleton.com>
parents:
2295
diff
changeset
|
125 |
PrintText(char *text) |
c97ad1abe05b
Minimal implementation of textinput events for x11. It only works for latin-1.
Bob Pendleton <bob@pendleton.com>
parents:
2295
diff
changeset
|
126 |
{ |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
127 |
SDL_Log("Text: %s", 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
|
128 |
} |
c97ad1abe05b
Minimal implementation of textinput events for x11. It only works for latin-1.
Bob Pendleton <bob@pendleton.com>
parents:
2295
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 |
#if __IPHONEOS__ |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
131 |
extern DECLSPEC int SDLCALL SDL_iPhoneKeyboardShow(SDL_Window * window); |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
132 |
#endif |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
133 |
|
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
|
134 |
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
|
135 |
main(int argc, char *argv[]) |
0 | 136 |
{ |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
137 |
SDL_Window *window; |
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
|
138 |
SDL_Event event; |
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
|
139 |
int done; |
0 | 140 |
|
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
|
141 |
/* 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
|
142 |
if (SDL_Init(SDL_INIT_VIDEO) < 0) { |
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
|
143 |
fprintf(stderr, "Couldn't initialize SDL: %s\n", 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
|
144 |
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
|
145 |
} |
0 | 146 |
|
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
|
147 |
/* 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
|
148 |
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
|
149 |
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
|
150 |
640, 480, 0); |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
151 |
if (!window) { |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
152 |
fprintf(stderr, "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
|
153 |
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
|
154 |
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
|
155 |
} |
0 | 156 |
|
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
157 |
#if __IPHONEOS__ |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
158 |
/* 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
|
159 |
SDL_GL_CreateContext(window); |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
160 |
SDL_iPhoneKeyboardShow(window); |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
161 |
#endif |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
162 |
|
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
163 |
|
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
|
164 |
/* 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
|
165 |
done = 0; |
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
|
166 |
while (!done) { |
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
|
167 |
/* Check for events */ |
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
|
168 |
SDL_WaitEvent(&event); |
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
|
169 |
switch (event.type) { |
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
|
170 |
case SDL_KEYDOWN: |
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
|
171 |
case SDL_KEYUP: |
4560
95352c671a6e
Added support for keyboard repeat (only tested on Windows so far)
Sam Lantinga <slouken@libsdl.org>
parents:
2315
diff
changeset
|
172 |
PrintKey(&event.key.keysym, event.key.state, event.key.repeat); |
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
|
173 |
break; |
2300
c97ad1abe05b
Minimal implementation of textinput events for x11. It only works for latin-1.
Bob Pendleton <bob@pendleton.com>
parents:
2295
diff
changeset
|
174 |
case SDL_TEXTINPUT: |
c97ad1abe05b
Minimal implementation of textinput events for x11. It only works for latin-1.
Bob Pendleton <bob@pendleton.com>
parents:
2295
diff
changeset
|
175 |
PrintText(event.text.text); |
c97ad1abe05b
Minimal implementation of textinput events for x11. It only works for latin-1.
Bob Pendleton <bob@pendleton.com>
parents:
2295
diff
changeset
|
176 |
break; |
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
|
177 |
case SDL_MOUSEBUTTONDOWN: |
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
|
178 |
/* Any button press quits the app... */ |
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
|
179 |
case 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
|
180 |
done = 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
|
181 |
break; |
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
|
182 |
default: |
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
|
183 |
break; |
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
|
184 |
} |
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
|
185 |
} |
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
|
186 |
|
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
|
187 |
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
|
188 |
return (0); |
0 | 189 |
} |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
190 |
|
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
191 |
/* vi: set ts=4 sw=4 expandtab: */ |