test/checkkeys.c
author Sam Lantinga <slouken@libsdl.org>
Fri, 08 Apr 2011 13:03:26 -0700
changeset 5535 96594ac5fd1a
parent 5461 94f742ce580a
child 5879 cdb371a9b4a1
permissions -rw-r--r--
SDL 1.3 is now under the zlib license.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    12
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    13
/* Simple program:  Loop, watching keystrokes
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    14
   Note that you need to call SDL_PollEvent() or SDL_WaitEvent() to 
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    15
   pump the event loop and catch keystrokes.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    16
*/
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    17
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    18
#include <stdio.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    19
#include <stdlib.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    20
#include <string.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    21
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    22
#include "SDL.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    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;
94f742ce580a Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents: 5218
diff changeset
    42
        if (len < *maxlen) {
94f742ce580a Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents: 5218
diff changeset
    43
            *maxlen -= len;
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
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    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
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    83
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    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
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    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),
94f742ce580a Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents: 5218
diff changeset
   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
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   110
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
   111
    /* 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
   112
    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
   113
        /* 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
   114
        if (sym->unicode < ' ') {
5461
94f742ce580a Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents: 5218
diff changeset
   115
            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
   116
        } else {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   117
#ifdef UNICODE
5461
94f742ce580a Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents: 5218
diff changeset
   118
            print_string(&spot, &left, " (%c)", sym->unicode);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   119
#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
   120
            /* 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
   121
            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
   122
                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
   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, " (0x%X)", sym->unicode);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   125
#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
   126
        }
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
   127
    }
5461
94f742ce580a Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents: 5218
diff changeset
   128
    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
   129
    if (repeat) {
5461
94f742ce580a Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents: 5218
diff changeset
   130
        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
   131
    }
5461
94f742ce580a Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents: 5218
diff changeset
   132
    SDL_Log("%s", message);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   133
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   134
2300
c97ad1abe05b Minimal implementation of textinput events for x11. It only works for latin-1.
Bob Pendleton <bob@pendleton.com>
parents: 2295
diff changeset
   135
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
   136
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
   137
{
5461
94f742ce580a Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents: 5218
diff changeset
   138
    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
   139
}
c97ad1abe05b Minimal implementation of textinput events for x11. It only works for latin-1.
Bob Pendleton <bob@pendleton.com>
parents: 2295
diff changeset
   140
5461
94f742ce580a Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents: 5218
diff changeset
   141
#if __IPHONEOS__
94f742ce580a Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents: 5218
diff changeset
   142
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
   143
#endif
94f742ce580a Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents: 5218
diff changeset
   144
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
   145
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
   146
main(int argc, char *argv[])
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   147
{
5461
94f742ce580a Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents: 5218
diff changeset
   148
    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
   149
    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
   150
    int done;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   151
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
   152
    /* 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
   153
    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
   154
        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
   155
        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
   156
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   157
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
   158
    /* 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
   159
    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
   160
                              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
   161
                              640, 480, 0);
94f742ce580a Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents: 5218
diff changeset
   162
    if (!window) {
94f742ce580a Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents: 5218
diff changeset
   163
        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
   164
                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
   165
        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
   166
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   167
5461
94f742ce580a Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents: 5218
diff changeset
   168
#if __IPHONEOS__
94f742ce580a Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents: 5218
diff changeset
   169
    /* 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
   170
    SDL_GL_CreateContext(window);
94f742ce580a Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents: 5218
diff changeset
   171
    SDL_iPhoneKeyboardShow(window);
94f742ce580a Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents: 5218
diff changeset
   172
#endif
94f742ce580a Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents: 5218
diff changeset
   173
    
94f742ce580a Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents: 5218
diff changeset
   174
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
   175
    /* 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
   176
    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
   177
    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
   178
        /* 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
   179
        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
   180
        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
   181
        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
   182
        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
   183
            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
   184
            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
   185
        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
   186
            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
   187
            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
   188
        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
   189
            /* 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
   190
        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
   191
            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
   192
            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
   193
        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
   194
            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
   195
        }
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
   196
    }
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
   197
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
   198
    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
   199
    return (0);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   200
}
5461
94f742ce580a Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents: 5218
diff changeset
   201
94f742ce580a Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Sam Lantinga <slouken@libsdl.org>
parents: 5218
diff changeset
   202
/* vi: set ts=4 sw=4 expandtab: */