author | Sam Lantinga <slouken@libsdl.org> |
Mon, 24 Jun 2013 22:06:50 -0700 | |
changeset 7317 | 37b77749523b |
parent 7312 | b36811d7db33 |
child 7517 | 965d57022c01 |
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 |
/* |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5461
diff
changeset
|
2 |
Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org> |
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 |
||
22 |
#include "SDL.h" |
|
23 |
||
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
|
24 |
/* 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
|
25 |
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
|
26 |
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
|
27 |
{ |
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
|
28 |
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
|
29 |
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
|
30 |
} |
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
|
31 |
|
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
|
32 |
static void |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
33 |
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
|
34 |
{ |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
35 |
int len; |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
36 |
va_list ap; |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
37 |
|
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
38 |
va_start(ap, fmt); |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
39 |
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
|
40 |
if (len > 0) { |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
41 |
*text += len; |
5879
cdb371a9b4a1
Fixed a compiler warning on Visual Studio.
Ryan C. Gordon <icculus@icculus.org>
parents:
5535
diff
changeset
|
42 |
if ( ((size_t) len) < *maxlen ) { |
cdb371a9b4a1
Fixed a compiler warning on Visual Studio.
Ryan C. Gordon <icculus@icculus.org>
parents:
5535
diff
changeset
|
43 |
*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
|
44 |
} else { |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
45 |
*maxlen = 0; |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
46 |
} |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
47 |
} |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
48 |
va_end(ap); |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
49 |
} |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
50 |
|
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
51 |
static void |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
52 |
print_modifiers(char **text, size_t *maxlen) |
0 | 53 |
{ |
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 |
int mod; |
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, " 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
|
56 |
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
|
57 |
if (!mod) { |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
58 |
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
|
59 |
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
|
60 |
} |
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
|
61 |
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
|
62 |
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
|
63 |
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
|
64 |
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
|
65 |
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
|
66 |
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
|
67 |
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
|
68 |
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
|
69 |
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
|
70 |
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
|
71 |
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
|
72 |
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
|
73 |
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
|
74 |
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
|
75 |
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
|
76 |
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
|
77 |
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
|
78 |
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
|
79 |
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
|
80 |
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
|
81 |
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
|
82 |
print_string(text, maxlen, " MODE"); |
0 | 83 |
} |
84 |
||
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 |
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
|
86 |
PrintKey(SDL_Keysym * sym, SDL_bool pressed, SDL_bool repeat) |
0 | 87 |
{ |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
88 |
char message[512]; |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
89 |
char *spot; |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
90 |
size_t left; |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
91 |
|
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
92 |
spot = message; |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
93 |
left = sizeof(message); |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
94 |
|
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
|
95 |
/* 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
|
96 |
if (sym->sym) { |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
97 |
print_string(&spot, &left, |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
98 |
"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
|
99 |
pressed ? "pressed " : "released", |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
100 |
sym->scancode, |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
101 |
SDL_GetScancodeName(sym->scancode), |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
102 |
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
|
103 |
} else { |
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, |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
105 |
"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
|
106 |
sym->scancode, |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
107 |
SDL_GetScancodeName(sym->scancode), |
6922 | 108 |
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
|
109 |
} |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
110 |
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
|
111 |
if (repeat) { |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
112 |
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
|
113 |
} |
6922 | 114 |
SDL_Log("%s\n", message); |
0 | 115 |
} |
116 |
||
2300
c97ad1abe05b
Minimal implementation of textinput events for x11. It only works for latin-1.
Bob Pendleton <bob@pendleton.com>
parents:
2295
diff
changeset
|
117 |
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
|
118 |
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
|
119 |
{ |
7317
37b77749523b
Better text printing for UTF-8 characters
Sam Lantinga <slouken@libsdl.org>
parents:
7312
diff
changeset
|
120 |
unsigned char *spot, expanded[1024]; |
37b77749523b
Better text printing for UTF-8 characters
Sam Lantinga <slouken@libsdl.org>
parents:
7312
diff
changeset
|
121 |
|
37b77749523b
Better text printing for UTF-8 characters
Sam Lantinga <slouken@libsdl.org>
parents:
7312
diff
changeset
|
122 |
expanded[0] = '\0'; |
37b77749523b
Better text printing for UTF-8 characters
Sam Lantinga <slouken@libsdl.org>
parents:
7312
diff
changeset
|
123 |
for ( spot = text; *spot; ++spot ) |
37b77749523b
Better text printing for UTF-8 characters
Sam Lantinga <slouken@libsdl.org>
parents:
7312
diff
changeset
|
124 |
{ |
37b77749523b
Better text printing for UTF-8 characters
Sam Lantinga <slouken@libsdl.org>
parents:
7312
diff
changeset
|
125 |
size_t length = SDL_strlen(expanded); |
37b77749523b
Better text printing for UTF-8 characters
Sam Lantinga <slouken@libsdl.org>
parents:
7312
diff
changeset
|
126 |
SDL_snprintf(expanded + length, sizeof(expanded) - length, "\\x%.2x", *spot); |
37b77749523b
Better text printing for UTF-8 characters
Sam Lantinga <slouken@libsdl.org>
parents:
7312
diff
changeset
|
127 |
} |
37b77749523b
Better text printing for UTF-8 characters
Sam Lantinga <slouken@libsdl.org>
parents:
7312
diff
changeset
|
128 |
SDL_Log("Text (%s): \"%s%s\"\n", 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
|
129 |
} |
c97ad1abe05b
Minimal implementation of textinput events for x11. It only works for latin-1.
Bob Pendleton <bob@pendleton.com>
parents:
2295
diff
changeset
|
130 |
|
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
|
131 |
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
|
132 |
main(int argc, char *argv[]) |
0 | 133 |
{ |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
134 |
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
|
135 |
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
|
136 |
int done; |
0 | 137 |
|
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 |
/* 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
|
139 |
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
|
140 |
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
|
141 |
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
|
142 |
} |
0 | 143 |
|
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
|
144 |
/* 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
|
145 |
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
|
146 |
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
|
147 |
640, 480, 0); |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
148 |
if (!window) { |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
149 |
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
|
150 |
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
|
151 |
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
|
152 |
} |
0 | 153 |
|
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
154 |
#if __IPHONEOS__ |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
155 |
/* 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
|
156 |
SDL_GL_CreateContext(window); |
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
157 |
#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
|
158 |
|
6654
2ecfb25be1e2
Synchronized the on-screen keyboard state with whether we are accepting text input.
Sam Lantinga <slouken@libsdl.org>
parents:
6392
diff
changeset
|
159 |
SDL_StartTextInput(); |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
160 |
|
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
|
161 |
/* 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
|
162 |
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
|
163 |
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
|
164 |
/* 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
|
165 |
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
|
166 |
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
|
167 |
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
|
168 |
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
|
169 |
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
|
170 |
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
|
171 |
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
|
172 |
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
|
173 |
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
|
174 |
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
|
175 |
/* 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
|
176 |
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
|
177 |
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
|
178 |
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
|
179 |
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
|
180 |
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
|
181 |
} |
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 |
} |
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
|
183 |
|
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
|
184 |
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
|
185 |
return (0); |
0 | 186 |
} |
5461
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
187 |
|
94f742ce580a
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents:
5218
diff
changeset
|
188 |
/* vi: set ts=4 sw=4 expandtab: */ |