1 /*
2   Simple DirectMedia Layer
3   Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
4 
5   This software is provided 'as-is', without any express or implied
6   warranty.  In no event will the authors be held liable for any damages
7   arising from the use of this software.
8 
9   Permission is granted to anyone to use this software for any purpose,
10   including commercial applications, and to alter it and redistribute it
11   freely, subject to the following restrictions:
12 
13   1. The origin of this software must not be misrepresented; you must not
14      claim that you wrote the original software. If you use this software
15      in a product, an acknowledgment in the product documentation would be
16      appreciated but is not required.
17   2. Altered source versions must be plainly marked as such, and must not be
18      misrepresented as being the original software.
19   3. This notice may not be removed or altered from any source distribution.
20 */
21 #include "../../SDL_internal.h"
22 
23 #if SDL_VIDEO_DRIVER_ANDROID
24 
25 #include <android/log.h>
26 
27 #include "../../events/SDL_events_c.h"
28 
29 #include "SDL_androidkeyboard.h"
30 
31 #include "../../core/android/SDL_android.h"
32 
Android_InitKeyboard(void)33 void Android_InitKeyboard(void)
34 {
35     SDL_Keycode keymap[SDL_NUM_SCANCODES];
36 
37     /* Add default scancode to key mapping */
38     SDL_GetDefaultKeymap(keymap);
39     SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES);
40 }
41 
42 static SDL_Scancode Android_Keycodes[] = {
43     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_UNKNOWN */
44     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_SOFT_LEFT */
45     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_SOFT_RIGHT */
46     SDL_SCANCODE_AC_HOME, /* AKEYCODE_HOME */
47     SDL_SCANCODE_AC_BACK, /* AKEYCODE_BACK */
48     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_CALL */
49     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_ENDCALL */
50     SDL_SCANCODE_0, /* AKEYCODE_0 */
51     SDL_SCANCODE_1, /* AKEYCODE_1 */
52     SDL_SCANCODE_2, /* AKEYCODE_2 */
53     SDL_SCANCODE_3, /* AKEYCODE_3 */
54     SDL_SCANCODE_4, /* AKEYCODE_4 */
55     SDL_SCANCODE_5, /* AKEYCODE_5 */
56     SDL_SCANCODE_6, /* AKEYCODE_6 */
57     SDL_SCANCODE_7, /* AKEYCODE_7 */
58     SDL_SCANCODE_8, /* AKEYCODE_8 */
59     SDL_SCANCODE_9, /* AKEYCODE_9 */
60     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_STAR */
61     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_POUND */
62     SDL_SCANCODE_UP, /* AKEYCODE_DPAD_UP */
63     SDL_SCANCODE_DOWN, /* AKEYCODE_DPAD_DOWN */
64     SDL_SCANCODE_LEFT, /* AKEYCODE_DPAD_LEFT */
65     SDL_SCANCODE_RIGHT, /* AKEYCODE_DPAD_RIGHT */
66     SDL_SCANCODE_SELECT, /* AKEYCODE_DPAD_CENTER */
67     SDL_SCANCODE_VOLUMEUP, /* AKEYCODE_VOLUME_UP */
68     SDL_SCANCODE_VOLUMEDOWN, /* AKEYCODE_VOLUME_DOWN */
69     SDL_SCANCODE_POWER, /* AKEYCODE_POWER */
70     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_CAMERA */
71     SDL_SCANCODE_CLEAR, /* AKEYCODE_CLEAR */
72     SDL_SCANCODE_A, /* AKEYCODE_A */
73     SDL_SCANCODE_B, /* AKEYCODE_B */
74     SDL_SCANCODE_C, /* AKEYCODE_C */
75     SDL_SCANCODE_D, /* AKEYCODE_D */
76     SDL_SCANCODE_E, /* AKEYCODE_E */
77     SDL_SCANCODE_F, /* AKEYCODE_F */
78     SDL_SCANCODE_G, /* AKEYCODE_G */
79     SDL_SCANCODE_H, /* AKEYCODE_H */
80     SDL_SCANCODE_I, /* AKEYCODE_I */
81     SDL_SCANCODE_J, /* AKEYCODE_J */
82     SDL_SCANCODE_K, /* AKEYCODE_K */
83     SDL_SCANCODE_L, /* AKEYCODE_L */
84     SDL_SCANCODE_M, /* AKEYCODE_M */
85     SDL_SCANCODE_N, /* AKEYCODE_N */
86     SDL_SCANCODE_O, /* AKEYCODE_O */
87     SDL_SCANCODE_P, /* AKEYCODE_P */
88     SDL_SCANCODE_Q, /* AKEYCODE_Q */
89     SDL_SCANCODE_R, /* AKEYCODE_R */
90     SDL_SCANCODE_S, /* AKEYCODE_S */
91     SDL_SCANCODE_T, /* AKEYCODE_T */
92     SDL_SCANCODE_U, /* AKEYCODE_U */
93     SDL_SCANCODE_V, /* AKEYCODE_V */
94     SDL_SCANCODE_W, /* AKEYCODE_W */
95     SDL_SCANCODE_X, /* AKEYCODE_X */
96     SDL_SCANCODE_Y, /* AKEYCODE_Y */
97     SDL_SCANCODE_Z, /* AKEYCODE_Z */
98     SDL_SCANCODE_COMMA, /* AKEYCODE_COMMA */
99     SDL_SCANCODE_PERIOD, /* AKEYCODE_PERIOD */
100     SDL_SCANCODE_LALT, /* AKEYCODE_ALT_LEFT */
101     SDL_SCANCODE_RALT, /* AKEYCODE_ALT_RIGHT */
102     SDL_SCANCODE_LSHIFT, /* AKEYCODE_SHIFT_LEFT */
103     SDL_SCANCODE_RSHIFT, /* AKEYCODE_SHIFT_RIGHT */
104     SDL_SCANCODE_TAB, /* AKEYCODE_TAB */
105     SDL_SCANCODE_SPACE, /* AKEYCODE_SPACE */
106     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_SYM */
107     SDL_SCANCODE_WWW, /* AKEYCODE_EXPLORER */
108     SDL_SCANCODE_MAIL, /* AKEYCODE_ENVELOPE */
109     SDL_SCANCODE_RETURN, /* AKEYCODE_ENTER */
110     SDL_SCANCODE_BACKSPACE, /* AKEYCODE_DEL */
111     SDL_SCANCODE_GRAVE, /* AKEYCODE_GRAVE */
112     SDL_SCANCODE_MINUS, /* AKEYCODE_MINUS */
113     SDL_SCANCODE_EQUALS, /* AKEYCODE_EQUALS */
114     SDL_SCANCODE_LEFTBRACKET, /* AKEYCODE_LEFT_BRACKET */
115     SDL_SCANCODE_RIGHTBRACKET, /* AKEYCODE_RIGHT_BRACKET */
116     SDL_SCANCODE_BACKSLASH, /* AKEYCODE_BACKSLASH */
117     SDL_SCANCODE_SEMICOLON, /* AKEYCODE_SEMICOLON */
118     SDL_SCANCODE_APOSTROPHE, /* AKEYCODE_APOSTROPHE */
119     SDL_SCANCODE_SLASH, /* AKEYCODE_SLASH */
120     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_AT */
121     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_NUM */
122     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_HEADSETHOOK */
123     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_FOCUS */
124     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_PLUS */
125     SDL_SCANCODE_MENU, /* AKEYCODE_MENU */
126     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_NOTIFICATION */
127     SDL_SCANCODE_AC_SEARCH, /* AKEYCODE_SEARCH */
128     SDL_SCANCODE_AUDIOPLAY, /* AKEYCODE_MEDIA_PLAY_PAUSE */
129     SDL_SCANCODE_AUDIOSTOP, /* AKEYCODE_MEDIA_STOP */
130     SDL_SCANCODE_AUDIONEXT, /* AKEYCODE_MEDIA_NEXT */
131     SDL_SCANCODE_AUDIOPREV, /* AKEYCODE_MEDIA_PREVIOUS */
132     SDL_SCANCODE_AUDIOREWIND, /* AKEYCODE_MEDIA_REWIND */
133     SDL_SCANCODE_AUDIOFASTFORWARD, /* AKEYCODE_MEDIA_FAST_FORWARD */
134     SDL_SCANCODE_MUTE, /* AKEYCODE_MUTE */
135     SDL_SCANCODE_PAGEUP, /* AKEYCODE_PAGE_UP */
136     SDL_SCANCODE_PAGEDOWN, /* AKEYCODE_PAGE_DOWN */
137     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_PICTSYMBOLS */
138     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_SWITCH_CHARSET */
139     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_A */
140     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_B */
141     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_C */
142     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_X */
143     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_Y */
144     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_Z */
145     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_L1 */
146     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_R1 */
147     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_L2 */
148     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_R2 */
149     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_THUMBL */
150     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_THUMBR */
151     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_START */
152     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_SELECT */
153     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_MODE */
154     SDL_SCANCODE_ESCAPE, /* AKEYCODE_ESCAPE */
155     SDL_SCANCODE_DELETE, /* AKEYCODE_FORWARD_DEL */
156     SDL_SCANCODE_LCTRL, /* AKEYCODE_CTRL_LEFT */
157     SDL_SCANCODE_RCTRL, /* AKEYCODE_CTRL_RIGHT */
158     SDL_SCANCODE_CAPSLOCK, /* AKEYCODE_CAPS_LOCK */
159     SDL_SCANCODE_SCROLLLOCK, /* AKEYCODE_SCROLL_LOCK */
160     SDL_SCANCODE_LGUI, /* AKEYCODE_META_LEFT */
161     SDL_SCANCODE_RGUI, /* AKEYCODE_META_RIGHT */
162     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_FUNCTION */
163     SDL_SCANCODE_PRINTSCREEN, /* AKEYCODE_SYSRQ */
164     SDL_SCANCODE_PAUSE, /* AKEYCODE_BREAK */
165     SDL_SCANCODE_HOME, /* AKEYCODE_MOVE_HOME */
166     SDL_SCANCODE_END, /* AKEYCODE_MOVE_END */
167     SDL_SCANCODE_INSERT, /* AKEYCODE_INSERT */
168     SDL_SCANCODE_AC_FORWARD, /* AKEYCODE_FORWARD */
169     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_PLAY */
170     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_PAUSE */
171     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_CLOSE */
172     SDL_SCANCODE_EJECT, /* AKEYCODE_MEDIA_EJECT */
173     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_RECORD */
174     SDL_SCANCODE_F1, /* AKEYCODE_F1 */
175     SDL_SCANCODE_F2, /* AKEYCODE_F2 */
176     SDL_SCANCODE_F3, /* AKEYCODE_F3 */
177     SDL_SCANCODE_F4, /* AKEYCODE_F4 */
178     SDL_SCANCODE_F5, /* AKEYCODE_F5 */
179     SDL_SCANCODE_F6, /* AKEYCODE_F6 */
180     SDL_SCANCODE_F7, /* AKEYCODE_F7 */
181     SDL_SCANCODE_F8, /* AKEYCODE_F8 */
182     SDL_SCANCODE_F9, /* AKEYCODE_F9 */
183     SDL_SCANCODE_F10, /* AKEYCODE_F10 */
184     SDL_SCANCODE_F11, /* AKEYCODE_F11 */
185     SDL_SCANCODE_F12, /* AKEYCODE_F12 */
186     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_NUM_LOCK */
187     SDL_SCANCODE_KP_0, /* AKEYCODE_NUMPAD_0 */
188     SDL_SCANCODE_KP_1, /* AKEYCODE_NUMPAD_1 */
189     SDL_SCANCODE_KP_2, /* AKEYCODE_NUMPAD_2 */
190     SDL_SCANCODE_KP_3, /* AKEYCODE_NUMPAD_3 */
191     SDL_SCANCODE_KP_4, /* AKEYCODE_NUMPAD_4 */
192     SDL_SCANCODE_KP_5, /* AKEYCODE_NUMPAD_5 */
193     SDL_SCANCODE_KP_6, /* AKEYCODE_NUMPAD_6 */
194     SDL_SCANCODE_KP_7, /* AKEYCODE_NUMPAD_7 */
195     SDL_SCANCODE_KP_8, /* AKEYCODE_NUMPAD_8 */
196     SDL_SCANCODE_KP_9, /* AKEYCODE_NUMPAD_9 */
197     SDL_SCANCODE_KP_DIVIDE, /* AKEYCODE_NUMPAD_DIVIDE */
198     SDL_SCANCODE_KP_MULTIPLY, /* AKEYCODE_NUMPAD_MULTIPLY */
199     SDL_SCANCODE_KP_MINUS, /* AKEYCODE_NUMPAD_SUBTRACT */
200     SDL_SCANCODE_KP_PLUS, /* AKEYCODE_NUMPAD_ADD */
201     SDL_SCANCODE_KP_PERIOD, /* AKEYCODE_NUMPAD_DOT */
202     SDL_SCANCODE_KP_COMMA, /* AKEYCODE_NUMPAD_COMMA */
203     SDL_SCANCODE_KP_ENTER, /* AKEYCODE_NUMPAD_ENTER */
204     SDL_SCANCODE_KP_EQUALS, /* AKEYCODE_NUMPAD_EQUALS */
205     SDL_SCANCODE_KP_LEFTPAREN, /* AKEYCODE_NUMPAD_LEFT_PAREN */
206     SDL_SCANCODE_KP_RIGHTPAREN, /* AKEYCODE_NUMPAD_RIGHT_PAREN */
207     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_VOLUME_MUTE */
208     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_INFO */
209     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_CHANNEL_UP */
210     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_CHANNEL_DOWN */
211     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_ZOOM_IN */
212     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_ZOOM_OUT */
213     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV */
214     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_WINDOW */
215     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_GUIDE */
216     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_DVR */
217     SDL_SCANCODE_AC_BOOKMARKS, /* AKEYCODE_BOOKMARK */
218     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_CAPTIONS */
219     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_SETTINGS */
220     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_POWER */
221     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_INPUT */
222     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_STB_POWER */
223     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_STB_INPUT */
224     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_AVR_POWER */
225     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_AVR_INPUT */
226     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_PROG_RED */
227     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_PROG_GREEN */
228     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_PROG_YELLOW */
229     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_PROG_BLUE */
230     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_APP_SWITCH */
231     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_1 */
232     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_2 */
233     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_3 */
234     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_4 */
235     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_5 */
236     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_6 */
237     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_7 */
238     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_8 */
239     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_9 */
240     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_10 */
241     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_11 */
242     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_12 */
243     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_13 */
244     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_14 */
245     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_15 */
246     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_16 */
247     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_LANGUAGE_SWITCH */
248     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MANNER_MODE */
249     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_3D_MODE */
250     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_CONTACTS */
251     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_CALENDAR */
252     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MUSIC */
253     SDL_SCANCODE_CALCULATOR, /* AKEYCODE_CALCULATOR */
254     SDL_SCANCODE_LANG5, /* AKEYCODE_ZENKAKU_HANKAKU */
255     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_EISU */
256     SDL_SCANCODE_INTERNATIONAL5, /* AKEYCODE_MUHENKAN */
257     SDL_SCANCODE_INTERNATIONAL4, /* AKEYCODE_HENKAN */
258     SDL_SCANCODE_LANG3, /* AKEYCODE_KATAKANA_HIRAGANA */
259     SDL_SCANCODE_INTERNATIONAL3, /* AKEYCODE_YEN */
260     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_RO */
261     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_KANA */
262     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_ASSIST */
263     SDL_SCANCODE_BRIGHTNESSDOWN, /* AKEYCODE_BRIGHTNESS_DOWN */
264     SDL_SCANCODE_BRIGHTNESSUP, /* AKEYCODE_BRIGHTNESS_UP */
265     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_AUDIO_TRACK */
266     SDL_SCANCODE_SLEEP, /* AKEYCODE_SLEEP */
267     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_WAKEUP */
268     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_PAIRING */
269     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_TOP_MENU */
270     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_11 */
271     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_12 */
272     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_LAST_CHANNEL */
273     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_DATA_SERVICE */
274     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_VOICE_ASSIST */
275     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_RADIO_SERVICE */
276     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_TELETEXT */
277     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_NUMBER_ENTRY */
278     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_TERRESTRIAL_ANALOG */
279     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_TERRESTRIAL_DIGITAL */
280     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_SATELLITE */
281     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_SATELLITE_BS */
282     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_SATELLITE_CS */
283     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_SATELLITE_SERVICE */
284     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_NETWORK */
285     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_ANTENNA_CABLE */
286     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_INPUT_HDMI_1 */
287     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_INPUT_HDMI_2 */
288     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_INPUT_HDMI_3 */
289     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_INPUT_HDMI_4 */
290     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_INPUT_COMPOSITE_1 */
291     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_INPUT_COMPOSITE_2 */
292     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_INPUT_COMPONENT_1 */
293     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_INPUT_COMPONENT_2 */
294     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_INPUT_VGA_1 */
295     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_AUDIO_DESCRIPTION */
296     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_AUDIO_DESCRIPTION_MIX_UP */
297     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_AUDIO_DESCRIPTION_MIX_DOWN */
298     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_ZOOM_MODE */
299     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_CONTENTS_MENU */
300     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_MEDIA_CONTEXT_MENU */
301     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_TIMER_PROGRAMMING */
302     SDL_SCANCODE_HELP, /* AKEYCODE_HELP */
303     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_NAVIGATE_PREVIOUS */
304     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_NAVIGATE_NEXT */
305     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_NAVIGATE_IN */
306     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_NAVIGATE_OUT */
307     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_STEM_PRIMARY */
308     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_STEM_1 */
309     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_STEM_2 */
310     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_STEM_3 */
311     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_DPAD_UP_LEFT */
312     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_DPAD_DOWN_LEFT */
313     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_DPAD_UP_RIGHT */
314     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_DPAD_DOWN_RIGHT */
315     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_SKIP_FORWARD */
316     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_SKIP_BACKWARD */
317     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_STEP_FORWARD */
318     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_STEP_BACKWARD */
319     SDL_SCANCODE_UNKNOWN, /* AKEYCODE_SOFT_SLEEP */
320     SDL_SCANCODE_CUT, /* AKEYCODE_CUT */
321     SDL_SCANCODE_COPY, /* AKEYCODE_COPY */
322     SDL_SCANCODE_PASTE, /* AKEYCODE_PASTE */
323 };
324 
325 static SDL_Scancode
TranslateKeycode(int keycode)326 TranslateKeycode(int keycode)
327 {
328     SDL_Scancode scancode = SDL_SCANCODE_UNKNOWN;
329 
330     if (keycode < SDL_arraysize(Android_Keycodes)) {
331         scancode = Android_Keycodes[keycode];
332     }
333     if (scancode == SDL_SCANCODE_UNKNOWN) {
334         __android_log_print(ANDROID_LOG_INFO, "SDL", "Unknown keycode %d", keycode);
335     }
336     return scancode;
337 }
338 
339 int
Android_OnKeyDown(int keycode)340 Android_OnKeyDown(int keycode)
341 {
342     return SDL_SendKeyboardKey(SDL_PRESSED, TranslateKeycode(keycode));
343 }
344 
345 int
Android_OnKeyUp(int keycode)346 Android_OnKeyUp(int keycode)
347 {
348     return SDL_SendKeyboardKey(SDL_RELEASED, TranslateKeycode(keycode));
349 }
350 
351 SDL_bool
Android_HasScreenKeyboardSupport(_THIS)352 Android_HasScreenKeyboardSupport(_THIS)
353 {
354     return SDL_TRUE;
355 }
356 
357 SDL_bool
Android_IsScreenKeyboardShown(_THIS,SDL_Window * window)358 Android_IsScreenKeyboardShown(_THIS, SDL_Window * window)
359 {
360     return Android_JNI_IsScreenKeyboardShown();
361 }
362 
363 void
Android_StartTextInput(_THIS)364 Android_StartTextInput(_THIS)
365 {
366     SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
367     Android_JNI_ShowTextInput(&videodata->textRect);
368 }
369 
370 void
Android_StopTextInput(_THIS)371 Android_StopTextInput(_THIS)
372 {
373     Android_JNI_HideTextInput();
374 }
375 
376 void
Android_SetTextInputRect(_THIS,SDL_Rect * rect)377 Android_SetTextInputRect(_THIS, SDL_Rect *rect)
378 {
379     SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
380 
381     if (!rect) {
382         SDL_InvalidParamError("rect");
383         return;
384     }
385 
386     videodata->textRect = *rect;
387 }
388 
389 #endif /* SDL_VIDEO_DRIVER_ANDROID */
390 
391 /* vi: set ts=4 sw=4 expandtab: */
392