AiCPlayer
Interface of aic vm - for rendering aspect, sensors, video records
sdl_translate.c
Go to the documentation of this file.
1 
5 #include <sdl_translate.h>
6 #include <linux/input.h>
7 
8 #include "logger.h"
9 #define LOG_TAG "sdl_translate"
10 
11 // clang-format off
12 /* Keep it consistent with linux/input.h */
13 typedef enum {
14  kKeyCodeEscape = KEY_ESC,
15  kKeyCodeHome = KEY_HOME,
16  kKeyCodeBack = KEY_BACK,
17  kKeyCodeCall = KEY_SEND,
18  kKeyCodeEndCall = KEY_END,
19  kKeyCode0 = KEY_0,
20  kKeyCode1 = KEY_1,
21  kKeyCode2 = KEY_2,
22  kKeyCode3 = KEY_3,
23  kKeyCode4 = KEY_4,
24  kKeyCode5 = KEY_5,
25  kKeyCode6 = KEY_6,
26  kKeyCode7 = KEY_7,
27  kKeyCode8 = KEY_8,
28  kKeyCode9 = KEY_9,
29  kKeyCodeStar = KEY_KPASTERISK,
30  kKeyCodeDpadUp = KEY_UP,
31  kKeyCodeDpadDown = KEY_DOWN,
32  kKeyCodeDpadLeft = KEY_LEFT,
33  kKeyCodeDpadRight = KEY_RIGHT,
34  kKeyCodeVolumeUp = KEY_VOLUMEUP,
35  kKeyCodeVolumeDown = KEY_VOLUMEDOWN,
36  kKeyCodePower = KEY_POWER,
37  kKeyCodeCamera = KEY_CAMERA,
38  kKeyCodeClear = KEY_CLEAR,
39  kKeyCodePageUp = KEY_PAGEUP,
40  kKeyCodePageDown = KEY_PAGEDOWN,
41  kKeyCodeA = KEY_A,
42  kKeyCodeB = KEY_B,
43  kKeyCodeC = KEY_C,
44  kKeyCodeD = KEY_D,
45  kKeyCodeE = KEY_E,
46  kKeyCodeF = KEY_F,
47  kKeyCodeG = KEY_G,
48  kKeyCodeH = KEY_H,
49  kKeyCodeI = KEY_I,
50  kKeyCodeJ = KEY_J,
51  kKeyCodeK = KEY_K,
52  kKeyCodeL = KEY_L,
53  kKeyCodeM = KEY_M,
54  kKeyCodeN = KEY_N,
55  kKeyCodeO = KEY_O,
56  kKeyCodeP = KEY_P,
57  kKeyCodeQ = KEY_Q,
58  kKeyCodeR = KEY_R,
59  kKeyCodeS = KEY_S,
60  kKeyCodeT = KEY_T,
61  kKeyCodeU = KEY_U,
62  kKeyCodeV = KEY_V,
63  kKeyCodeW = KEY_W,
64  kKeyCodeX = KEY_X,
65  kKeyCodeY = KEY_Y,
66  kKeyCodeZ = KEY_Z,
67 
68  kKeyCodeComma = KEY_COMMA,
69  kKeyCodePeriod = KEY_DOT,
70  kKeyCodeAltLeft = KEY_LEFTALT,
71  kKeyCodeAltRight = KEY_RIGHTALT,
72  kKeyCodeCapLeft = KEY_LEFTSHIFT,
73  kKeyCodeCapRight = KEY_RIGHTSHIFT,
74  kKeyCodeTab = KEY_TAB,
75  kKeyCodeSpace = KEY_SPACE,
76  kKeyCodeSym = KEY_COMPOSE,
77  kKeyCodeExplorer = KEY_WWW,
78  kKeyCodeEnvelope = KEY_MAIL,
79  kKeyCodeNewline = KEY_ENTER,
80  kKeyCodeDel = KEY_BACKSPACE,
82  kKeyCodeMinus = KEY_MINUS,
83  kKeyCodeEquals = KEY_EQUAL,
84  kKeyCodeLeftBracket = KEY_LEFTBRACE,
85  kKeyCodeRightBracket = KEY_RIGHTBRACE,
86  kKeyCodeBackslash = KEY_BACKSLASH,
87  kKeyCodeSemicolon = KEY_SEMICOLON,
88  kKeyCodeApostrophe = KEY_APOSTROPHE,
89  kKeyCodeSlash = KEY_SLASH,
90  kKeyCodeAt = KEY_EMAIL,
91  kKeyCodeSearch = KEY_SEARCH,
92  kKeyCodePrevious = KEY_PREVIOUS,
93  kKeyCodeNext = KEY_NEXT,
94  kKeyCodePlay = KEY_PLAY,
95  kKeyCodePause = KEY_PAUSE,
96  kKeyCodeStop = KEY_STOP,
97  kKeyCodeRewind = KEY_REWIND,
98  kKeyCodeFastForward = KEY_FASTFORWARD,
99  kKeyCodeBookmarks = KEY_BOOKMARKS,
100  kKeyCodeCycleWindows = KEY_CYCLEWINDOWS,
101 
103 
104 
105 int sdl_translate_event(SDL_Scancode scancode, SDL_Keycode keysym)
106 {
107  (void) keysym;
108  switch(scancode) {
109  case SDL_SCANCODE_ESCAPE: return kKeyCodeEscape;
110  case SDL_SCANCODE_1: return kKeyCode1;
111  case SDL_SCANCODE_2: return kKeyCode2;
112  case SDL_SCANCODE_3: return kKeyCode3;
113  case SDL_SCANCODE_4: return kKeyCode4;
114  case SDL_SCANCODE_5: return kKeyCode5;
115  case SDL_SCANCODE_6: return kKeyCode6;
116  case SDL_SCANCODE_7: return kKeyCode7;
117  case SDL_SCANCODE_8: return kKeyCode8;
118  case SDL_SCANCODE_9: return kKeyCode9;
119  case SDL_SCANCODE_0: return kKeyCode0;
120 
121  case SDL_SCANCODE_Q: return kKeyCodeQ;
122  case SDL_SCANCODE_W: return kKeyCodeW;
123  case SDL_SCANCODE_E: return kKeyCodeE;
124  case SDL_SCANCODE_R: return kKeyCodeR;
125  case SDL_SCANCODE_T: return kKeyCodeT;
126  case SDL_SCANCODE_Y: return kKeyCodeY;
127  case SDL_SCANCODE_U: return kKeyCodeU;
128  case SDL_SCANCODE_I: return kKeyCodeI;
129  case SDL_SCANCODE_O: return kKeyCodeO;
130  case SDL_SCANCODE_P: return kKeyCodeP;
131  case SDL_SCANCODE_A: return kKeyCodeA;
132  case SDL_SCANCODE_S: return kKeyCodeS;
133  case SDL_SCANCODE_D: return kKeyCodeD;
134  case SDL_SCANCODE_F: return kKeyCodeF;
135  case SDL_SCANCODE_G: return kKeyCodeG;
136  case SDL_SCANCODE_H: return kKeyCodeH;
137  case SDL_SCANCODE_J: return kKeyCodeJ;
138  case SDL_SCANCODE_K: return kKeyCodeK;
139  case SDL_SCANCODE_L: return kKeyCodeL;
140  case SDL_SCANCODE_Z: return kKeyCodeZ;
141  case SDL_SCANCODE_X: return kKeyCodeX;
142  case SDL_SCANCODE_C: return kKeyCodeC;
143  case SDL_SCANCODE_V: return kKeyCodeV;
144  case SDL_SCANCODE_B: return kKeyCodeB;
145  case SDL_SCANCODE_N: return kKeyCodeN;
146  case SDL_SCANCODE_M: return kKeyCodeM;
147  case SDL_SCANCODE_COMMA: return kKeyCodeComma;
148  case SDL_SCANCODE_PERIOD: return kKeyCodePeriod;
149  case SDL_SCANCODE_SPACE: return kKeyCodeSpace;
150  case SDL_SCANCODE_SLASH: return kKeyCodeSlash;
151  case SDL_SCANCODE_RETURN: return kKeyCodeNewline;
152  case SDL_SCANCODE_BACKSPACE: return kKeyCodeDel;
153 
154 /* these are qwerty keys not on a device keyboard */
155  case SDL_SCANCODE_TAB: return kKeyCodeTab;
156  case SDL_SCANCODE_GRAVE : return kKeyCodeGrave;
157  case SDL_SCANCODE_MINUS: return kKeyCodeMinus;
158  case SDL_SCANCODE_EQUALS: return kKeyCodeEquals;
159  case SDL_SCANCODE_LEFTBRACKET: return kKeyCodeLeftBracket;
160  case SDL_SCANCODE_RIGHTBRACKET: return kKeyCodeRightBracket;
161  case SDL_SCANCODE_BACKSLASH: return kKeyCodeBackslash;
162  case SDL_SCANCODE_SEMICOLON: return kKeyCodeSemicolon;
163  case SDL_SCANCODE_APOSTROPHE: return kKeyCodeApostrophe;
164 
165  case SDL_SCANCODE_UP: return kKeyCodeDpadUp;
166  case SDL_SCANCODE_DOWN: return kKeyCodeDpadDown;
167  case SDL_SCANCODE_LEFT: return kKeyCodeDpadLeft;
168  case SDL_SCANCODE_RIGHT: return kKeyCodeDpadRight;
169  case SDL_SCANCODE_PAGEUP: return kKeyCodePageUp;
170  case SDL_SCANCODE_PAGEDOWN: return kKeyCodePageDown;
171 
172  case SDL_SCANCODE_RSHIFT: return kKeyCodeCapRight;
173  case SDL_SCANCODE_LSHIFT: return kKeyCodeCapLeft;
174  case SDL_SCANCODE_RALT: return kKeyCodeAltRight;
175  case SDL_SCANCODE_LALT: return kKeyCodeAltLeft;
176  case SDL_SCANCODE_RCTRL: return kKeyCodeSym;
177  case SDL_SCANCODE_LCTRL: return kKeyCodeSym;
178 
179  default:
180  LOGW("unknown sdl scancode %d", scancode);
181  return -1;
182  }
183 }
184 // clang-format on
AndroidKeyCode
Definition: sdl_translate.c:13
int sdl_translate_event(SDL_Scancode scancode, SDL_Keycode keysym)
Convert an SDL scancode to a value read by the virtual input daemon.
Logging macros.
Convert sdl events to uinput codes.
#define LOGW(...)
Log at WARNING level.
Definition: logger.h:27