6900
|
1 |
/*
|
|
2 |
Simple DirectMedia Layer
|
|
3 |
Copyright (C) 1997-2012 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_config.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 |
#include "SDL_keycode.h"
|
|
31 |
|
|
32 |
|
|
33 |
void Android_InitKeyboard()
|
|
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_UNKNOWN, /* AKEYCODE_EXPLORER */
|
|
108 |
SDL_SCANCODE_UNKNOWN, /* 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_UNKNOWN, /* 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_UNKNOWN, /* AKEYCODE_MEDIA_REWIND */
|
|
133 |
SDL_SCANCODE_UNKNOWN, /* 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 |
};
|
|
155 |
|
|
156 |
static SDL_Scancode
|
|
157 |
TranslateKeycode(int keycode)
|
|
158 |
{
|
|
159 |
SDL_Scancode scancode = SDL_SCANCODE_UNKNOWN;
|
|
160 |
|
|
161 |
if (keycode < SDL_arraysize(Android_Keycodes)) {
|
|
162 |
scancode = Android_Keycodes[keycode];
|
|
163 |
}
|
|
164 |
if (scancode == SDL_SCANCODE_UNKNOWN) {
|
|
165 |
__android_log_print(ANDROID_LOG_INFO, "SDL", "Unknown keycode %d", keycode);
|
|
166 |
}
|
|
167 |
__android_log_print(ANDROID_LOG_INFO, "SDLXELI", "keycode %d scancode %d", keycode, scancode);
|
|
168 |
return scancode;
|
|
169 |
}
|
|
170 |
|
|
171 |
int
|
|
172 |
Android_OnKeyDown(int keycode)
|
|
173 |
{
|
|
174 |
return SDL_SendKeyboardKey(SDL_PRESSED, TranslateKeycode(keycode));
|
|
175 |
}
|
|
176 |
|
|
177 |
int
|
|
178 |
Android_OnKeyUp(int keycode)
|
|
179 |
{
|
|
180 |
return SDL_SendKeyboardKey(SDL_RELEASED, TranslateKeycode(keycode));
|
|
181 |
}
|
|
182 |
|
|
183 |
#endif /* SDL_VIDEO_DRIVER_ANDROID */
|
|
184 |
|
|
185 |
/* vi: set ts=4 sw=4 expandtab: */
|