Commit 95c839f4 authored by Sam Lantinga's avatar Sam Lantinga

Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)

parent 608ec7da
...@@ -290,6 +290,7 @@ ...@@ -290,6 +290,7 @@
SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_LSHIFT); SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_LSHIFT);
} }
} }
SDL_SendKeyboardText([string UTF8String]);
} }
return NO; /* don't allow the edit! (keep placeholder text there) */ return NO; /* don't allow the edit! (keep placeholder text there) */
} }
......
...@@ -19,92 +19,124 @@ quit(int rc) ...@@ -19,92 +19,124 @@ quit(int rc)
} }
static void static void
print_modifiers(void) print_string(char **text, size_t *maxlen, const char *fmt, ...)
{
int len;
va_list ap;
va_start(ap, fmt);
len = SDL_vsnprintf(*text, *maxlen, fmt, ap);
if (len > 0) {
*text += len;
if (len < *maxlen) {
*maxlen -= len;
} else {
*maxlen = 0;
}
}
va_end(ap);
}
static void
print_modifiers(char **text, size_t *maxlen)
{ {
int mod; int mod;
printf(" modifiers:"); print_string(text, maxlen, " modifiers:");
mod = SDL_GetModState(); mod = SDL_GetModState();
if (!mod) { if (!mod) {
printf(" (none)"); print_string(text, maxlen, " (none)");
return; return;
} }
if (mod & KMOD_LSHIFT) if (mod & KMOD_LSHIFT)
printf(" LSHIFT"); print_string(text, maxlen, " LSHIFT");
if (mod & KMOD_RSHIFT) if (mod & KMOD_RSHIFT)
printf(" RSHIFT"); print_string(text, maxlen, " RSHIFT");
if (mod & KMOD_LCTRL) if (mod & KMOD_LCTRL)
printf(" LCTRL"); print_string(text, maxlen, " LCTRL");
if (mod & KMOD_RCTRL) if (mod & KMOD_RCTRL)
printf(" RCTRL"); print_string(text, maxlen, " RCTRL");
if (mod & KMOD_LALT) if (mod & KMOD_LALT)
printf(" LALT"); print_string(text, maxlen, " LALT");
if (mod & KMOD_RALT) if (mod & KMOD_RALT)
printf(" RALT"); print_string(text, maxlen, " RALT");
if (mod & KMOD_LGUI) if (mod & KMOD_LGUI)
printf(" LGUI"); print_string(text, maxlen, " LGUI");
if (mod & KMOD_RGUI) if (mod & KMOD_RGUI)
printf(" RGUI"); print_string(text, maxlen, " RGUI");
if (mod & KMOD_NUM) if (mod & KMOD_NUM)
printf(" NUM"); print_string(text, maxlen, " NUM");
if (mod & KMOD_CAPS) if (mod & KMOD_CAPS)
printf(" CAPS"); print_string(text, maxlen, " CAPS");
if (mod & KMOD_MODE) if (mod & KMOD_MODE)
printf(" MODE"); print_string(text, maxlen, " MODE");
} }
static void static void
PrintKey(SDL_Keysym * sym, SDL_bool pressed, SDL_bool repeat) PrintKey(SDL_Keysym * sym, SDL_bool pressed, SDL_bool repeat)
{ {
char message[512];
char *spot;
size_t left;
spot = message;
left = sizeof(message);
/* Print the keycode, name and state */ /* Print the keycode, name and state */
if (sym->sym) { if (sym->sym) {
printf("Key %s: scancode %d = %s, keycode 0x%08X = %s ", print_string(&spot, &left,
pressed ? "pressed " : "released", "Key %s: scancode %d = %s, keycode 0x%08X = %s ",
sym->scancode, pressed ? "pressed " : "released",
SDL_GetScancodeName(sym->scancode), sym->scancode,
sym->sym, SDL_GetKeyName(sym->sym)); SDL_GetScancodeName(sym->scancode),
sym->sym, SDL_GetKeyName(sym->sym));
} else { } else {
printf("Unknown Key (scancode %d = %s) %s ", print_string(&spot, &left,
sym->scancode, "Unknown Key (scancode %d = %s) %s ",
SDL_GetScancodeName(sym->scancode), sym->scancode,
pressed ? "pressed" : "released"); SDL_GetScancodeName(sym->scancode),
pressed ? "pressed" : "released");
} }
/* Print the translated character, if one exists */ /* Print the translated character, if one exists */
if (sym->unicode) { if (sym->unicode) {
/* Is it a control-character? */ /* Is it a control-character? */
if (sym->unicode < ' ') { if (sym->unicode < ' ') {
printf(" (^%c)", sym->unicode + '@'); print_string(&spot, &left, " (^%c)", sym->unicode + '@');
} else { } else {
#ifdef UNICODE #ifdef UNICODE
printf(" (%c)", sym->unicode); print_string(&spot, &left, " (%c)", sym->unicode);
#else #else
/* This is a Latin-1 program, so only show 8-bits */ /* This is a Latin-1 program, so only show 8-bits */
if (!(sym->unicode & 0xFF00)) if (!(sym->unicode & 0xFF00))
printf(" (%c)", sym->unicode); print_string(&spot, &left, " (%c)", sym->unicode);
else else
printf(" (0x%X)", sym->unicode); print_string(&spot, &left, " (0x%X)", sym->unicode);
#endif #endif
} }
} }
print_modifiers(); print_modifiers(&spot, &left);
if (repeat) { if (repeat) {
printf(" (repeat)"); print_string(&spot, &left, " (repeat)");
} }
printf("\n"); SDL_Log("%s", message);
} }
static void static void
PrintText(char *text) PrintText(char *text)
{ {
printf("Text: %s\n", text); SDL_Log("Text: %s", text);
} }
#if __IPHONEOS__
extern DECLSPEC int SDLCALL SDL_iPhoneKeyboardShow(SDL_Window * window);
#endif
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
SDL_Window *window;
SDL_Event event; SDL_Event event;
int done; int done;
Uint32 videoflags;
/* Initialize SDL */ /* Initialize SDL */
if (SDL_Init(SDL_INIT_VIDEO) < 0) { if (SDL_Init(SDL_INIT_VIDEO) < 0) {
...@@ -112,24 +144,23 @@ main(int argc, char *argv[]) ...@@ -112,24 +144,23 @@ main(int argc, char *argv[])
return (1); return (1);
} }
videoflags = SDL_SWSURFACE;
while (argc > 1) {
--argc;
if (argv[argc] && !strcmp(argv[argc], "-fullscreen")) {
videoflags |= SDL_FULLSCREEN;
} else {
fprintf(stderr, "Usage: %s [-fullscreen]\n", argv[0]);
quit(1);
}
}
/* Set 640x480 video mode */ /* Set 640x480 video mode */
if (SDL_SetVideoMode(640, 480, 0, videoflags) == NULL) { window = SDL_CreateWindow("CheckKeys Test",
fprintf(stderr, "Couldn't set 640x480 video mode: %s\n", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
640, 480, 0);
if (!window) {
fprintf(stderr, "Couldn't create 640x480 window: %s\n",
SDL_GetError()); SDL_GetError());
quit(2); quit(2);
} }
#if __IPHONEOS__
/* Creating the context creates the view, which we need to show keyboard */
SDL_GL_CreateContext(window);
SDL_iPhoneKeyboardShow(window);
#endif
/* Watch keystrokes */ /* Watch keystrokes */
done = 0; done = 0;
while (!done) { while (!done) {
...@@ -156,3 +187,5 @@ main(int argc, char *argv[]) ...@@ -156,3 +187,5 @@ main(int argc, char *argv[])
SDL_Quit(); SDL_Quit();
return (0); return (0);
} }
/* vi: set ts=4 sw=4 expandtab: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment