src/video/android/SDL_androidkeyboard.c
changeset 4993 3c9058f3ffe7
parent 4980 d9fdff945ec9
child 5081 25d4feb7c127
     1.1 --- a/src/video/android/SDL_androidkeyboard.c	Wed Jan 12 21:21:08 2011 -0800
     1.2 +++ b/src/video/android/SDL_androidkeyboard.c	Wed Jan 12 21:21:21 2011 -0800
     1.3 @@ -21,6 +21,8 @@
     1.4  */
     1.5  #include "SDL_config.h"
     1.6  
     1.7 +#include <android/log.h>
     1.8 +
     1.9  #include "../../events/SDL_events_c.h"
    1.10  
    1.11  #include "SDL_androidkeyboard.h"
    1.12 @@ -35,18 +37,144 @@
    1.13      SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES);
    1.14  }
    1.15  
    1.16 +static SDL_scancode Android_Keycodes[] = {
    1.17 +    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_UNKNOWN */
    1.18 +    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_SOFT_LEFT */
    1.19 +    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_SOFT_RIGHT */
    1.20 +    SDL_SCANCODE_AC_HOME, /* AKEYCODE_HOME */
    1.21 +    SDL_SCANCODE_AC_BACK, /* AKEYCODE_BACK */
    1.22 +    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_CALL */
    1.23 +    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_ENDCALL */
    1.24 +    SDL_SCANCODE_0, /* AKEYCODE_0 */
    1.25 +    SDL_SCANCODE_1, /* AKEYCODE_1 */
    1.26 +    SDL_SCANCODE_2, /* AKEYCODE_2 */
    1.27 +    SDL_SCANCODE_3, /* AKEYCODE_3 */
    1.28 +    SDL_SCANCODE_4, /* AKEYCODE_4 */
    1.29 +    SDL_SCANCODE_5, /* AKEYCODE_5 */
    1.30 +    SDL_SCANCODE_6, /* AKEYCODE_6 */
    1.31 +    SDL_SCANCODE_7, /* AKEYCODE_7 */
    1.32 +    SDL_SCANCODE_8, /* AKEYCODE_8 */
    1.33 +    SDL_SCANCODE_9, /* AKEYCODE_9 */
    1.34 +    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_STAR */
    1.35 +    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_POUND */
    1.36 +    SDL_SCANCODE_UP, /* AKEYCODE_DPAD_UP */
    1.37 +    SDL_SCANCODE_DOWN, /* AKEYCODE_DPAD_DOWN */
    1.38 +    SDL_SCANCODE_LEFT, /* AKEYCODE_DPAD_LEFT */
    1.39 +    SDL_SCANCODE_RIGHT, /* AKEYCODE_DPAD_RIGHT */
    1.40 +    SDL_SCANCODE_SELECT, /* AKEYCODE_DPAD_CENTER */
    1.41 +    SDL_SCANCODE_VOLUMEUP, /* AKEYCODE_VOLUME_UP */
    1.42 +    SDL_SCANCODE_VOLUMEDOWN, /* AKEYCODE_VOLUME_DOWN */
    1.43 +    SDL_SCANCODE_POWER, /* AKEYCODE_POWER */
    1.44 +    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_CAMERA */
    1.45 +    SDL_SCANCODE_CLEAR, /* AKEYCODE_CLEAR */
    1.46 +    SDL_SCANCODE_A, /* AKEYCODE_A */
    1.47 +    SDL_SCANCODE_B, /* AKEYCODE_B */
    1.48 +    SDL_SCANCODE_C, /* AKEYCODE_C */
    1.49 +    SDL_SCANCODE_D, /* AKEYCODE_D */
    1.50 +    SDL_SCANCODE_E, /* AKEYCODE_E */
    1.51 +    SDL_SCANCODE_F, /* AKEYCODE_F */
    1.52 +    SDL_SCANCODE_G, /* AKEYCODE_G */
    1.53 +    SDL_SCANCODE_H, /* AKEYCODE_H */
    1.54 +    SDL_SCANCODE_I, /* AKEYCODE_I */
    1.55 +    SDL_SCANCODE_J, /* AKEYCODE_J */
    1.56 +    SDL_SCANCODE_K, /* AKEYCODE_K */
    1.57 +    SDL_SCANCODE_L, /* AKEYCODE_L */
    1.58 +    SDL_SCANCODE_M, /* AKEYCODE_M */
    1.59 +    SDL_SCANCODE_N, /* AKEYCODE_N */
    1.60 +    SDL_SCANCODE_O, /* AKEYCODE_O */
    1.61 +    SDL_SCANCODE_P, /* AKEYCODE_P */
    1.62 +    SDL_SCANCODE_Q, /* AKEYCODE_Q */
    1.63 +    SDL_SCANCODE_R, /* AKEYCODE_R */
    1.64 +    SDL_SCANCODE_S, /* AKEYCODE_S */
    1.65 +    SDL_SCANCODE_T, /* AKEYCODE_T */
    1.66 +    SDL_SCANCODE_U, /* AKEYCODE_U */
    1.67 +    SDL_SCANCODE_V, /* AKEYCODE_V */
    1.68 +    SDL_SCANCODE_W, /* AKEYCODE_W */
    1.69 +    SDL_SCANCODE_X, /* AKEYCODE_X */
    1.70 +    SDL_SCANCODE_Y, /* AKEYCODE_Y */
    1.71 +    SDL_SCANCODE_Z, /* AKEYCODE_Z */
    1.72 +    SDL_SCANCODE_COMMA, /* AKEYCODE_COMMA */
    1.73 +    SDL_SCANCODE_PERIOD, /* AKEYCODE_PERIOD */
    1.74 +    SDL_SCANCODE_LALT, /* AKEYCODE_ALT_LEFT */
    1.75 +    SDL_SCANCODE_RALT, /* AKEYCODE_ALT_RIGHT */
    1.76 +    SDL_SCANCODE_LSHIFT, /* AKEYCODE_SHIFT_LEFT */
    1.77 +    SDL_SCANCODE_RSHIFT, /* AKEYCODE_SHIFT_RIGHT */
    1.78 +    SDL_SCANCODE_TAB, /* AKEYCODE_TAB */
    1.79 +    SDL_SCANCODE_SPACE, /* AKEYCODE_SPACE */
    1.80 +    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_SYM */
    1.81 +    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_EXPLORER */
    1.82 +    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_ENVELOPE */
    1.83 +    SDL_SCANCODE_RETURN, /* AKEYCODE_ENTER */
    1.84 +    SDL_SCANCODE_DELETE, /* AKEYCODE_DEL */
    1.85 +    SDL_SCANCODE_GRAVE, /* AKEYCODE_GRAVE */
    1.86 +    SDL_SCANCODE_MINUS, /* AKEYCODE_MINUS */
    1.87 +    SDL_SCANCODE_EQUALS, /* AKEYCODE_EQUALS */
    1.88 +    SDL_SCANCODE_LEFTBRACKET, /* AKEYCODE_LEFT_BRACKET */
    1.89 +    SDL_SCANCODE_RIGHTBRACKET, /* AKEYCODE_RIGHT_BRACKET */
    1.90 +    SDL_SCANCODE_BACKSLASH, /* AKEYCODE_BACKSLASH */
    1.91 +    SDL_SCANCODE_SEMICOLON, /* AKEYCODE_SEMICOLON */
    1.92 +    SDL_SCANCODE_APOSTROPHE, /* AKEYCODE_APOSTROPHE */
    1.93 +    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_SLASH */
    1.94 +    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_AT */
    1.95 +    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_NUM */
    1.96 +    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_HEADSETHOOK */
    1.97 +    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_FOCUS */
    1.98 +    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_PLUS */
    1.99 +    SDL_SCANCODE_MENU, /* AKEYCODE_MENU */
   1.100 +    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_NOTIFICATION */
   1.101 +    SDL_SCANCODE_AC_SEARCH, /* AKEYCODE_SEARCH */
   1.102 +    SDL_SCANCODE_AUDIOPLAY, /* AKEYCODE_MEDIA_PLAY_PAUSE */
   1.103 +    SDL_SCANCODE_AUDIOSTOP, /* AKEYCODE_MEDIA_STOP */
   1.104 +    SDL_SCANCODE_AUDIONEXT, /* AKEYCODE_MEDIA_NEXT */
   1.105 +    SDL_SCANCODE_AUDIOPREV, /* AKEYCODE_MEDIA_PREVIOUS */
   1.106 +    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_REWIND */
   1.107 +    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_FAST_FORWARD */
   1.108 +    SDL_SCANCODE_MUTE, /* AKEYCODE_MUTE */
   1.109 +    SDL_SCANCODE_PAGEUP, /* AKEYCODE_PAGE_UP */
   1.110 +    SDL_SCANCODE_PAGEDOWN, /* AKEYCODE_PAGE_DOWN */
   1.111 +    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_PICTSYMBOLS */
   1.112 +    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_SWITCH_CHARSET */
   1.113 +    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_A */
   1.114 +    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_B */
   1.115 +    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_C */
   1.116 +    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_X */
   1.117 +    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_Y */
   1.118 +    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_Z */
   1.119 +    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_L1 */
   1.120 +    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_R1 */
   1.121 +    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_L2 */
   1.122 +    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_R2 */
   1.123 +    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_THUMBL */
   1.124 +    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_THUMBR */
   1.125 +    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_START */
   1.126 +    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_SELECT */
   1.127 +    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_MODE */
   1.128 +};
   1.129 +
   1.130 +static SDL_scancode
   1.131 +TranslateKeycode(int keycode)
   1.132 +{
   1.133 +    SDL_scancode scancode = SDL_SCANCODE_UNKNOWN;
   1.134 +
   1.135 +    if (keycode < SDL_arraysize(Android_Keycodes)) {
   1.136 +        scancode = Android_Keycodes[keycode];
   1.137 +    }
   1.138 +    if (scancode == SDL_SCANCODE_UNKNOWN) {
   1.139 +        __android_log_print(ANDROID_LOG_INFO, "SDL", "Unknown keycode %d", keycode);
   1.140 +    }
   1.141 +    return scancode;
   1.142 +}
   1.143 +
   1.144  int
   1.145  Android_OnKeyDown(int keycode)
   1.146  {
   1.147 -    /* FIXME: Need conversion from Android keycode to SDL scancode */
   1.148 -    return SDL_SendKeyboardKey(SDL_PRESSED, (SDL_scancode)keycode);
   1.149 +    return SDL_SendKeyboardKey(SDL_PRESSED, TranslateKeycode(keycode));
   1.150  }
   1.151  
   1.152  int
   1.153  Android_OnKeyUp(int keycode)
   1.154  {
   1.155 -    /* FIXME: Need conversion from Android keycode to SDL scancode */
   1.156 -    return SDL_SendKeyboardKey(SDL_RELEASED, (SDL_scancode)keycode);
   1.157 +    return SDL_SendKeyboardKey(SDL_RELEASED, TranslateKeycode(keycode));
   1.158  }
   1.159  
   1.160  /* vi: set ts=4 sw=4 expandtab: */