comparison src/video/android/SDL_androidkeyboard.c @ 4993:3c9058f3ffe7

Implemented translation from Android keycodes to SDL scancodes
author Sam Lantinga <slouken@libsdl.org>
date Wed, 12 Jan 2011 21:21:21 -0800
parents d9fdff945ec9
children 25d4feb7c127
comparison
equal deleted inserted replaced
4992:b12d76ef05e2 4993:3c9058f3ffe7
19 Sam Lantinga 19 Sam Lantinga
20 slouken@libsdl.org 20 slouken@libsdl.org
21 */ 21 */
22 #include "SDL_config.h" 22 #include "SDL_config.h"
23 23
24 #include <android/log.h>
25
24 #include "../../events/SDL_events_c.h" 26 #include "../../events/SDL_events_c.h"
25 27
26 #include "SDL_androidkeyboard.h" 28 #include "SDL_androidkeyboard.h"
27 29
28 30
33 /* Add default scancode to key mapping */ 35 /* Add default scancode to key mapping */
34 SDL_GetDefaultKeymap(keymap); 36 SDL_GetDefaultKeymap(keymap);
35 SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES); 37 SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES);
36 } 38 }
37 39
40 static SDL_scancode Android_Keycodes[] = {
41 SDL_SCANCODE_UNKNOWN, /* AKEYCODE_UNKNOWN */
42 SDL_SCANCODE_UNKNOWN, /* AKEYCODE_SOFT_LEFT */
43 SDL_SCANCODE_UNKNOWN, /* AKEYCODE_SOFT_RIGHT */
44 SDL_SCANCODE_AC_HOME, /* AKEYCODE_HOME */
45 SDL_SCANCODE_AC_BACK, /* AKEYCODE_BACK */
46 SDL_SCANCODE_UNKNOWN, /* AKEYCODE_CALL */
47 SDL_SCANCODE_UNKNOWN, /* AKEYCODE_ENDCALL */
48 SDL_SCANCODE_0, /* AKEYCODE_0 */
49 SDL_SCANCODE_1, /* AKEYCODE_1 */
50 SDL_SCANCODE_2, /* AKEYCODE_2 */
51 SDL_SCANCODE_3, /* AKEYCODE_3 */
52 SDL_SCANCODE_4, /* AKEYCODE_4 */
53 SDL_SCANCODE_5, /* AKEYCODE_5 */
54 SDL_SCANCODE_6, /* AKEYCODE_6 */
55 SDL_SCANCODE_7, /* AKEYCODE_7 */
56 SDL_SCANCODE_8, /* AKEYCODE_8 */
57 SDL_SCANCODE_9, /* AKEYCODE_9 */
58 SDL_SCANCODE_UNKNOWN, /* AKEYCODE_STAR */
59 SDL_SCANCODE_UNKNOWN, /* AKEYCODE_POUND */
60 SDL_SCANCODE_UP, /* AKEYCODE_DPAD_UP */
61 SDL_SCANCODE_DOWN, /* AKEYCODE_DPAD_DOWN */
62 SDL_SCANCODE_LEFT, /* AKEYCODE_DPAD_LEFT */
63 SDL_SCANCODE_RIGHT, /* AKEYCODE_DPAD_RIGHT */
64 SDL_SCANCODE_SELECT, /* AKEYCODE_DPAD_CENTER */
65 SDL_SCANCODE_VOLUMEUP, /* AKEYCODE_VOLUME_UP */
66 SDL_SCANCODE_VOLUMEDOWN, /* AKEYCODE_VOLUME_DOWN */
67 SDL_SCANCODE_POWER, /* AKEYCODE_POWER */
68 SDL_SCANCODE_UNKNOWN, /* AKEYCODE_CAMERA */
69 SDL_SCANCODE_CLEAR, /* AKEYCODE_CLEAR */
70 SDL_SCANCODE_A, /* AKEYCODE_A */
71 SDL_SCANCODE_B, /* AKEYCODE_B */
72 SDL_SCANCODE_C, /* AKEYCODE_C */
73 SDL_SCANCODE_D, /* AKEYCODE_D */
74 SDL_SCANCODE_E, /* AKEYCODE_E */
75 SDL_SCANCODE_F, /* AKEYCODE_F */
76 SDL_SCANCODE_G, /* AKEYCODE_G */
77 SDL_SCANCODE_H, /* AKEYCODE_H */
78 SDL_SCANCODE_I, /* AKEYCODE_I */
79 SDL_SCANCODE_J, /* AKEYCODE_J */
80 SDL_SCANCODE_K, /* AKEYCODE_K */
81 SDL_SCANCODE_L, /* AKEYCODE_L */
82 SDL_SCANCODE_M, /* AKEYCODE_M */
83 SDL_SCANCODE_N, /* AKEYCODE_N */
84 SDL_SCANCODE_O, /* AKEYCODE_O */
85 SDL_SCANCODE_P, /* AKEYCODE_P */
86 SDL_SCANCODE_Q, /* AKEYCODE_Q */
87 SDL_SCANCODE_R, /* AKEYCODE_R */
88 SDL_SCANCODE_S, /* AKEYCODE_S */
89 SDL_SCANCODE_T, /* AKEYCODE_T */
90 SDL_SCANCODE_U, /* AKEYCODE_U */
91 SDL_SCANCODE_V, /* AKEYCODE_V */
92 SDL_SCANCODE_W, /* AKEYCODE_W */
93 SDL_SCANCODE_X, /* AKEYCODE_X */
94 SDL_SCANCODE_Y, /* AKEYCODE_Y */
95 SDL_SCANCODE_Z, /* AKEYCODE_Z */
96 SDL_SCANCODE_COMMA, /* AKEYCODE_COMMA */
97 SDL_SCANCODE_PERIOD, /* AKEYCODE_PERIOD */
98 SDL_SCANCODE_LALT, /* AKEYCODE_ALT_LEFT */
99 SDL_SCANCODE_RALT, /* AKEYCODE_ALT_RIGHT */
100 SDL_SCANCODE_LSHIFT, /* AKEYCODE_SHIFT_LEFT */
101 SDL_SCANCODE_RSHIFT, /* AKEYCODE_SHIFT_RIGHT */
102 SDL_SCANCODE_TAB, /* AKEYCODE_TAB */
103 SDL_SCANCODE_SPACE, /* AKEYCODE_SPACE */
104 SDL_SCANCODE_UNKNOWN, /* AKEYCODE_SYM */
105 SDL_SCANCODE_UNKNOWN, /* AKEYCODE_EXPLORER */
106 SDL_SCANCODE_UNKNOWN, /* AKEYCODE_ENVELOPE */
107 SDL_SCANCODE_RETURN, /* AKEYCODE_ENTER */
108 SDL_SCANCODE_DELETE, /* AKEYCODE_DEL */
109 SDL_SCANCODE_GRAVE, /* AKEYCODE_GRAVE */
110 SDL_SCANCODE_MINUS, /* AKEYCODE_MINUS */
111 SDL_SCANCODE_EQUALS, /* AKEYCODE_EQUALS */
112 SDL_SCANCODE_LEFTBRACKET, /* AKEYCODE_LEFT_BRACKET */
113 SDL_SCANCODE_RIGHTBRACKET, /* AKEYCODE_RIGHT_BRACKET */
114 SDL_SCANCODE_BACKSLASH, /* AKEYCODE_BACKSLASH */
115 SDL_SCANCODE_SEMICOLON, /* AKEYCODE_SEMICOLON */
116 SDL_SCANCODE_APOSTROPHE, /* AKEYCODE_APOSTROPHE */
117 SDL_SCANCODE_UNKNOWN, /* AKEYCODE_SLASH */
118 SDL_SCANCODE_UNKNOWN, /* AKEYCODE_AT */
119 SDL_SCANCODE_UNKNOWN, /* AKEYCODE_NUM */
120 SDL_SCANCODE_UNKNOWN, /* AKEYCODE_HEADSETHOOK */
121 SDL_SCANCODE_UNKNOWN, /* AKEYCODE_FOCUS */
122 SDL_SCANCODE_UNKNOWN, /* AKEYCODE_PLUS */
123 SDL_SCANCODE_MENU, /* AKEYCODE_MENU */
124 SDL_SCANCODE_UNKNOWN, /* AKEYCODE_NOTIFICATION */
125 SDL_SCANCODE_AC_SEARCH, /* AKEYCODE_SEARCH */
126 SDL_SCANCODE_AUDIOPLAY, /* AKEYCODE_MEDIA_PLAY_PAUSE */
127 SDL_SCANCODE_AUDIOSTOP, /* AKEYCODE_MEDIA_STOP */
128 SDL_SCANCODE_AUDIONEXT, /* AKEYCODE_MEDIA_NEXT */
129 SDL_SCANCODE_AUDIOPREV, /* AKEYCODE_MEDIA_PREVIOUS */
130 SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_REWIND */
131 SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_FAST_FORWARD */
132 SDL_SCANCODE_MUTE, /* AKEYCODE_MUTE */
133 SDL_SCANCODE_PAGEUP, /* AKEYCODE_PAGE_UP */
134 SDL_SCANCODE_PAGEDOWN, /* AKEYCODE_PAGE_DOWN */
135 SDL_SCANCODE_UNKNOWN, /* AKEYCODE_PICTSYMBOLS */
136 SDL_SCANCODE_UNKNOWN, /* AKEYCODE_SWITCH_CHARSET */
137 SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_A */
138 SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_B */
139 SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_C */
140 SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_X */
141 SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_Y */
142 SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_Z */
143 SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_L1 */
144 SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_R1 */
145 SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_L2 */
146 SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_R2 */
147 SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_THUMBL */
148 SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_THUMBR */
149 SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_START */
150 SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_SELECT */
151 SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_MODE */
152 };
153
154 static SDL_scancode
155 TranslateKeycode(int keycode)
156 {
157 SDL_scancode scancode = SDL_SCANCODE_UNKNOWN;
158
159 if (keycode < SDL_arraysize(Android_Keycodes)) {
160 scancode = Android_Keycodes[keycode];
161 }
162 if (scancode == SDL_SCANCODE_UNKNOWN) {
163 __android_log_print(ANDROID_LOG_INFO, "SDL", "Unknown keycode %d", keycode);
164 }
165 return scancode;
166 }
167
38 int 168 int
39 Android_OnKeyDown(int keycode) 169 Android_OnKeyDown(int keycode)
40 { 170 {
41 /* FIXME: Need conversion from Android keycode to SDL scancode */ 171 return SDL_SendKeyboardKey(SDL_PRESSED, TranslateKeycode(keycode));
42 return SDL_SendKeyboardKey(SDL_PRESSED, (SDL_scancode)keycode);
43 } 172 }
44 173
45 int 174 int
46 Android_OnKeyUp(int keycode) 175 Android_OnKeyUp(int keycode)
47 { 176 {
48 /* FIXME: Need conversion from Android keycode to SDL scancode */ 177 return SDL_SendKeyboardKey(SDL_RELEASED, TranslateKeycode(keycode));
49 return SDL_SendKeyboardKey(SDL_RELEASED, (SDL_scancode)keycode);
50 } 178 }
51 179
52 /* vi: set ts=4 sw=4 expandtab: */ 180 /* vi: set ts=4 sw=4 expandtab: */