1 | /* |
---|
2 | orxonox - the future of 3D-vertical-scrollers |
---|
3 | |
---|
4 | Copyright (C) 2004 orx |
---|
5 | |
---|
6 | This program is free software; you can redistribute it and/or modify |
---|
7 | it under the terms of the GNU General Public License as published by |
---|
8 | the Free Software Foundation; either version 2, or (at your option) |
---|
9 | any later version. |
---|
10 | |
---|
11 | ### File Specific: |
---|
12 | main-programmer: Christian Meyer |
---|
13 | co-programmer: ... |
---|
14 | */ |
---|
15 | |
---|
16 | #include "key_names.h" |
---|
17 | #include "event_def.h" |
---|
18 | |
---|
19 | std::string EVToKeyName(int key) |
---|
20 | { |
---|
21 | std::string name = SDLBToButtonname( key ); |
---|
22 | if (name != "UNKNOWN") |
---|
23 | return name; |
---|
24 | else |
---|
25 | return SDLKToKeyname( key ); |
---|
26 | } |
---|
27 | |
---|
28 | int KeyNameToEV(const std::string& keyName) |
---|
29 | { |
---|
30 | int key = buttonnameToSDLB( keyName ); |
---|
31 | if (key != -1) |
---|
32 | return key; |
---|
33 | else |
---|
34 | return keynameToSDLK( keyName ); |
---|
35 | } |
---|
36 | |
---|
37 | |
---|
38 | int buttonnameToSDLB(const std::string& name) |
---|
39 | { |
---|
40 | if((name == "BUTTON_LEFT")) return EV_MOUSE_BUTTON_LEFT; |
---|
41 | if((name == "BUTTON_MIDDLE")) return EV_MOUSE_BUTTON_MIDDLE; |
---|
42 | if((name == "BUTTON_RIGHT")) return EV_MOUSE_BUTTON_RIGHT; |
---|
43 | if((name == "BUTTON_WHEELUP")) return EV_MOUSE_BUTTON_WHEELUP; |
---|
44 | if((name == "BUTTON_WHEELDOWN")) return EV_MOUSE_BUTTON_WHEELDOWN; |
---|
45 | return -1; |
---|
46 | } |
---|
47 | |
---|
48 | std::string SDLBToButtonname( int button) |
---|
49 | { |
---|
50 | if( button == EV_MOUSE_BUTTON_LEFT) return "BUTTON_LEFT"; |
---|
51 | if( button == EV_MOUSE_BUTTON_MIDDLE) return "BUTTON_MIDDLE"; |
---|
52 | if( button == EV_MOUSE_BUTTON_RIGHT) return "BUTTON_RIGHT"; |
---|
53 | if( button == EV_MOUSE_BUTTON_WHEELUP) return "BUTTON_WHEELUP"; |
---|
54 | if( button == EV_MOUSE_BUTTON_WHEELDOWN) return "BUTTON_WHEELDOWN"; |
---|
55 | return "UNKNOWN"; |
---|
56 | } |
---|
57 | |
---|
58 | int keynameToSDLK(const std::string& name) |
---|
59 | { |
---|
60 | if((name == "BACKSPACE")) return SDLK_BACKSPACE; |
---|
61 | if((name == "TAB")) return SDLK_TAB; |
---|
62 | if((name == "CLEAR")) return SDLK_CLEAR; |
---|
63 | if((name == "RETURN")) return SDLK_RETURN; |
---|
64 | if((name == "ESCAPE")) return SDLK_ESCAPE; |
---|
65 | if((name == "SPACE")) return SDLK_SPACE; |
---|
66 | if((name == "EXCLAIM")) return SDLK_EXCLAIM; |
---|
67 | if((name == "QUOTEDBL")) return SDLK_QUOTEDBL; |
---|
68 | if((name == "HASH")) return SDLK_HASH; |
---|
69 | if((name == "PAUSE")) return SDLK_PAUSE; |
---|
70 | if((name == "DOLLAR")) return SDLK_DOLLAR; |
---|
71 | if((name == "AMPERSAND")) return SDLK_AMPERSAND; |
---|
72 | if((name == "QUOTE")) return SDLK_QUOTE; |
---|
73 | if((name == "LEFTPAREN")) return SDLK_LEFTPAREN; |
---|
74 | if((name == "RIGHTPAREN")) return SDLK_RIGHTPAREN; |
---|
75 | if((name == "ASTERISK")) return SDLK_ASTERISK; |
---|
76 | if((name == "PLUS")) return SDLK_PLUS; |
---|
77 | if((name == "COMMA")) return SDLK_COMMA; |
---|
78 | if((name == "MINUS")) return SDLK_MINUS; |
---|
79 | if((name == "PERIOD")) return SDLK_PERIOD; |
---|
80 | if((name == "SLASH")) return SDLK_SLASH; |
---|
81 | if((name == "0")) return SDLK_0; |
---|
82 | if((name == "1")) return SDLK_1; |
---|
83 | if((name == "2")) return SDLK_2; |
---|
84 | if((name == "3")) return SDLK_3; |
---|
85 | if((name == "4")) return SDLK_4; |
---|
86 | if((name == "5")) return SDLK_5; |
---|
87 | if((name == "6")) return SDLK_6; |
---|
88 | if((name == "7")) return SDLK_7; |
---|
89 | if((name == "8")) return SDLK_8; |
---|
90 | if((name == "9")) return SDLK_9; |
---|
91 | if((name == "COLON")) return SDLK_COLON; |
---|
92 | if((name == "SEMICOLON")) return SDLK_SEMICOLON; |
---|
93 | if((name == "LESS")) return SDLK_LESS; |
---|
94 | if((name == "EQUALS")) return SDLK_EQUALS; |
---|
95 | if((name == "GREATER")) return SDLK_GREATER; |
---|
96 | if((name == "QUESTION")) return SDLK_QUESTION; |
---|
97 | if((name == "AT")) return SDLK_AT; |
---|
98 | if((name == "LEFTBRACKET")) return SDLK_LEFTBRACKET; |
---|
99 | if((name == "BACKSLASH")) return SDLK_BACKSLASH; |
---|
100 | if((name == "RIGHTBRACKET")) return SDLK_RIGHTBRACKET; |
---|
101 | if((name == "CARET")) return SDLK_CARET; |
---|
102 | if((name == "UNDERSCORE")) return SDLK_UNDERSCORE; |
---|
103 | if((name == "BACKQUOTE")) return SDLK_BACKQUOTE; |
---|
104 | if((name == "a")) return SDLK_a; |
---|
105 | if((name == "b")) return SDLK_b; |
---|
106 | if((name == "c")) return SDLK_c; |
---|
107 | if((name == "d")) return SDLK_d; |
---|
108 | if((name == "e")) return SDLK_e; |
---|
109 | if((name == "f")) return SDLK_f; |
---|
110 | if((name == "g")) return SDLK_g; |
---|
111 | if((name == "h")) return SDLK_h; |
---|
112 | if((name == "i")) return SDLK_i; |
---|
113 | if((name == "j")) return SDLK_j; |
---|
114 | if((name == "k")) return SDLK_k; |
---|
115 | if((name == "l")) return SDLK_l; |
---|
116 | if((name == "m")) return SDLK_m; |
---|
117 | if((name == "n")) return SDLK_n; |
---|
118 | if((name == "o")) return SDLK_o; |
---|
119 | if((name == "p")) return SDLK_p; |
---|
120 | if((name == "q")) return SDLK_q; |
---|
121 | if((name == "r")) return SDLK_r; |
---|
122 | if((name == "s")) return SDLK_s; |
---|
123 | if((name == "t")) return SDLK_t; |
---|
124 | if((name == "u")) return SDLK_u; |
---|
125 | if((name == "v")) return SDLK_v; |
---|
126 | if((name == "w")) return SDLK_w; |
---|
127 | if((name == "x")) return SDLK_x; |
---|
128 | if((name == "y")) return SDLK_y; |
---|
129 | if((name == "z")) return SDLK_z; |
---|
130 | if((name == "DELETE")) return SDLK_DELETE; |
---|
131 | if((name == "KP0")) return SDLK_KP0; |
---|
132 | if((name == "KP1")) return SDLK_KP1; |
---|
133 | if((name == "KP2")) return SDLK_KP2; |
---|
134 | if((name == "KP3")) return SDLK_KP3; |
---|
135 | if((name == "KP4")) return SDLK_KP4; |
---|
136 | if((name == "KP5")) return SDLK_KP5; |
---|
137 | if((name == "KP6")) return SDLK_KP6; |
---|
138 | if((name == "KP7")) return SDLK_KP7; |
---|
139 | if((name == "KP8")) return SDLK_KP8; |
---|
140 | if((name == "KP9")) return SDLK_KP9; |
---|
141 | if((name == "KP_PERIOD")) return SDLK_KP_PERIOD; |
---|
142 | if((name == "KP_DIVIDE")) return SDLK_KP_DIVIDE; |
---|
143 | if((name == "KP_MULTIPLY")) return SDLK_KP_MULTIPLY; |
---|
144 | if((name == "KP_MINUS")) return SDLK_KP_MINUS; |
---|
145 | if((name == "KP_PLUS")) return SDLK_KP_PLUS; |
---|
146 | if((name == "KP_ENTER")) return SDLK_KP_ENTER; |
---|
147 | if((name == "KP_EQUALS")) return SDLK_KP_EQUALS; |
---|
148 | if((name == "UP")) return SDLK_UP; |
---|
149 | if((name == "DOWN")) return SDLK_DOWN; |
---|
150 | if((name == "RIGHT")) return SDLK_RIGHT; |
---|
151 | if((name == "LEFT")) return SDLK_LEFT; |
---|
152 | if((name == "INSERT")) return SDLK_INSERT; |
---|
153 | if((name == "HOME")) return SDLK_HOME; |
---|
154 | if((name == "END")) return SDLK_END; |
---|
155 | if((name == "PAGEUP")) return SDLK_PAGEUP; |
---|
156 | if((name == "PAGEDOWN")) return SDLK_PAGEDOWN; |
---|
157 | if((name == "F1")) return SDLK_F1; |
---|
158 | if((name == "F2")) return SDLK_F2; |
---|
159 | if((name == "F3")) return SDLK_F3; |
---|
160 | if((name == "F4")) return SDLK_F4; |
---|
161 | if((name == "F5")) return SDLK_F5; |
---|
162 | if((name == "F6")) return SDLK_F6; |
---|
163 | if((name == "F7")) return SDLK_F7; |
---|
164 | if((name == "F8")) return SDLK_F8; |
---|
165 | if((name == "F9")) return SDLK_F9; |
---|
166 | if((name == "F10")) return SDLK_F10; |
---|
167 | if((name == "F11")) return SDLK_F11; |
---|
168 | if((name == "F12")) return SDLK_F12; |
---|
169 | if((name == "F13")) return SDLK_F13; |
---|
170 | if((name == "F14")) return SDLK_F14; |
---|
171 | if((name == "F15")) return SDLK_F15; |
---|
172 | if((name == "NUMLOCK")) return SDLK_NUMLOCK; |
---|
173 | if((name == "CAPSLOCK")) return SDLK_CAPSLOCK; |
---|
174 | if((name == "SCROLLOCK")) return SDLK_SCROLLOCK; |
---|
175 | if((name == "RSHIFT")) return SDLK_RSHIFT; |
---|
176 | if((name == "LSHIFT")) return SDLK_LSHIFT; |
---|
177 | if((name == "RCTRL")) return SDLK_RCTRL; |
---|
178 | if((name == "LCTRL")) return SDLK_LCTRL; |
---|
179 | if((name == "RALT")) return SDLK_RALT; |
---|
180 | if((name == "LALT")) return SDLK_LALT; |
---|
181 | if((name == "RMETA")) return SDLK_RMETA; |
---|
182 | if((name == "LMETA")) return SDLK_LMETA; |
---|
183 | if((name == "LSUPER")) return SDLK_LSUPER; |
---|
184 | if((name == "RSUPER")) return SDLK_RSUPER; |
---|
185 | if((name == "MODE")) return SDLK_MODE; |
---|
186 | if((name == "HELP")) return SDLK_HELP; |
---|
187 | if((name == "PRINT")) return SDLK_PRINT; |
---|
188 | if((name == "SYSREQ")) return SDLK_SYSREQ; |
---|
189 | if((name == "BREAK")) return SDLK_BREAK; |
---|
190 | if((name == "MENU")) return SDLK_MENU; |
---|
191 | if((name == "POWER")) return SDLK_POWER; |
---|
192 | if((name == "EURO")) return SDLK_EURO; |
---|
193 | return -1; |
---|
194 | } |
---|
195 | |
---|
196 | std::string SDLKToKeyname(int key) |
---|
197 | { |
---|
198 | if( key == SDLK_BACKSPACE) return "BACKSPACE"; |
---|
199 | if( key == SDLK_TAB) return "TAB"; |
---|
200 | if( key == SDLK_CLEAR) return "CLEAR"; |
---|
201 | if( key == SDLK_RETURN) return "RETURN"; |
---|
202 | if( key == SDLK_SPACE) return "SPACE"; |
---|
203 | if( key == SDLK_ESCAPE) return "ESCAPE"; |
---|
204 | if( key == SDLK_EXCLAIM) return "EXCLAIM"; |
---|
205 | if( key == SDLK_QUOTEDBL) return "QUOTEDBL"; |
---|
206 | if( key == SDLK_HASH) return "HASH"; |
---|
207 | if( key == SDLK_PAUSE) return "PAUSE"; |
---|
208 | if( key == SDLK_DOLLAR) return "DOLLAR"; |
---|
209 | if( key == SDLK_AMPERSAND) return "AMPERSAND"; |
---|
210 | if( key == SDLK_QUOTE) return "QUOTE"; |
---|
211 | if( key == SDLK_LEFTPAREN) return "LEFTPAREN"; |
---|
212 | if( key == SDLK_RIGHTPAREN) return "RIGHTPAREN"; |
---|
213 | if( key == SDLK_ASTERISK) return "ASTERISK"; |
---|
214 | if( key == SDLK_PLUS) return "PLUS"; |
---|
215 | if( key == SDLK_COMMA) return "COMMA"; |
---|
216 | if( key == SDLK_MINUS) return "MINUS"; |
---|
217 | if( key == SDLK_PERIOD) return "PERIOD"; |
---|
218 | if( key == SDLK_SLASH) return "SLASH"; |
---|
219 | if( key == SDLK_0) return "0"; |
---|
220 | if( key == SDLK_1) return "1"; |
---|
221 | if( key == SDLK_2) return "2"; |
---|
222 | if( key == SDLK_3) return "3"; |
---|
223 | if( key == SDLK_4) return "4"; |
---|
224 | if( key == SDLK_5) return "5"; |
---|
225 | if( key == SDLK_6) return "6"; |
---|
226 | if( key == SDLK_7) return "7"; |
---|
227 | if( key == SDLK_8) return "8"; |
---|
228 | if( key == SDLK_9) return "9"; |
---|
229 | if( key == SDLK_COLON) return "COLON"; |
---|
230 | if( key == SDLK_SEMICOLON) return "SEMICOLON"; |
---|
231 | if( key == SDLK_LESS) return "LESS"; |
---|
232 | if( key == SDLK_EQUALS) return "EQUALS"; |
---|
233 | if( key == SDLK_GREATER) return "GREATER"; |
---|
234 | if( key == SDLK_QUESTION) return "QUESTION"; |
---|
235 | if( key == SDLK_AT) return "AT"; |
---|
236 | if( key == SDLK_LEFTBRACKET) return "LEFTBRACKET"; |
---|
237 | if( key == SDLK_BACKSLASH) return "BACKSLASH"; |
---|
238 | if( key == SDLK_RIGHTBRACKET) return "RIGHTBRACKET"; |
---|
239 | if( key == SDLK_CARET) return "CARET"; |
---|
240 | if( key == SDLK_UNDERSCORE) return "UNDERSCORE"; |
---|
241 | if( key == SDLK_BACKQUOTE) return "BACKQUOTE"; |
---|
242 | if( key == SDLK_a) return "a"; |
---|
243 | if( key == SDLK_b) return "b"; |
---|
244 | if( key == SDLK_c) return "c"; |
---|
245 | if( key == SDLK_d) return "d"; |
---|
246 | if( key == SDLK_e) return "e"; |
---|
247 | if( key == SDLK_f) return "f"; |
---|
248 | if( key == SDLK_g) return "g"; |
---|
249 | if( key == SDLK_h) return "h"; |
---|
250 | if( key == SDLK_i) return "i"; |
---|
251 | if( key == SDLK_j) return "j"; |
---|
252 | if( key == SDLK_k) return "k"; |
---|
253 | if( key == SDLK_l) return "l"; |
---|
254 | if( key == SDLK_m) return "m"; |
---|
255 | if( key == SDLK_n) return "n"; |
---|
256 | if( key == SDLK_o) return "o"; |
---|
257 | if( key == SDLK_p) return "p"; |
---|
258 | if( key == SDLK_q) return "q"; |
---|
259 | if( key == SDLK_r) return "r"; |
---|
260 | if( key == SDLK_s) return "s"; |
---|
261 | if( key == SDLK_t) return "t"; |
---|
262 | if( key == SDLK_u) return "u"; |
---|
263 | if( key == SDLK_v) return "v"; |
---|
264 | if( key == SDLK_w) return "w"; |
---|
265 | if( key == SDLK_x) return "x"; |
---|
266 | if( key == SDLK_y) return "y"; |
---|
267 | if( key == SDLK_z) return "z"; |
---|
268 | if( key == SDLK_DELETE) return "DELETE"; |
---|
269 | if( key == SDLK_KP0) return "KP0"; |
---|
270 | if( key == SDLK_KP1) return "KP1"; |
---|
271 | if( key == SDLK_KP2) return "KP2"; |
---|
272 | if( key == SDLK_KP3) return "KP3"; |
---|
273 | if( key == SDLK_KP4) return "KP4"; |
---|
274 | if( key == SDLK_KP5) return "KP5"; |
---|
275 | if( key == SDLK_KP6) return "KP6"; |
---|
276 | if( key == SDLK_KP7) return "KP7"; |
---|
277 | if( key == SDLK_KP8) return "KP8"; |
---|
278 | if( key == SDLK_KP9) return "KP9"; |
---|
279 | if( key == SDLK_KP_PERIOD) return "KP_PERIOD"; |
---|
280 | if( key == SDLK_KP_DIVIDE) return "KP_DIVIDE"; |
---|
281 | if( key == SDLK_KP_MULTIPLY) return "KP_MULTIPLY"; |
---|
282 | if( key == SDLK_KP_MINUS) return "KP_MINUS"; |
---|
283 | if( key == SDLK_KP_PLUS) return "KP_PLUS"; |
---|
284 | if( key == SDLK_KP_ENTER) return "KP_ENTER"; |
---|
285 | if( key == SDLK_KP_EQUALS) return "KP_EQUALS"; |
---|
286 | if( key == SDLK_UP) return "UP"; |
---|
287 | if( key == SDLK_DOWN) return "DOWN"; |
---|
288 | if( key == SDLK_RIGHT) return "RIGHT"; |
---|
289 | if( key == SDLK_LEFT) return "LEFT"; |
---|
290 | if( key == SDLK_INSERT) return "INSERT"; |
---|
291 | if( key == SDLK_HOME) return "HOME"; |
---|
292 | if( key == SDLK_END) return "END"; |
---|
293 | if( key == SDLK_PAGEUP) return "PAGEUP"; |
---|
294 | if( key == SDLK_PAGEDOWN) return "PAGEDOWN"; |
---|
295 | if( key == SDLK_F1) return "F1"; |
---|
296 | if( key == SDLK_F2) return "F2"; |
---|
297 | if( key == SDLK_F3) return "F3"; |
---|
298 | if( key == SDLK_F4) return "F4"; |
---|
299 | if( key == SDLK_F5) return "F5"; |
---|
300 | if( key == SDLK_F6) return "F6"; |
---|
301 | if( key == SDLK_F7) return "F7"; |
---|
302 | if( key == SDLK_F8) return "F8"; |
---|
303 | if( key == SDLK_F9) return "F9"; |
---|
304 | if( key == SDLK_F10) return "F10"; |
---|
305 | if( key == SDLK_F11) return "F11"; |
---|
306 | if( key == SDLK_F12) return "F12"; |
---|
307 | if( key == SDLK_F13) return "F13"; |
---|
308 | if( key == SDLK_F14) return "F14"; |
---|
309 | if( key == SDLK_F15) return "F15"; |
---|
310 | if( key == SDLK_NUMLOCK) return "NUMLOCK"; |
---|
311 | if( key == SDLK_CAPSLOCK) return "CAPSLOCK"; |
---|
312 | if( key == SDLK_SCROLLOCK) return "SCROLLOCK"; |
---|
313 | if( key == SDLK_RSHIFT) return "RSHIFT"; |
---|
314 | if( key == SDLK_LSHIFT) return "LSHIFT"; |
---|
315 | if( key == SDLK_RCTRL) return "RCTRL"; |
---|
316 | if( key == SDLK_LCTRL) return "LCTRL"; |
---|
317 | if( key == SDLK_RALT) return "RALT"; |
---|
318 | if( key == SDLK_LALT) return "LALT"; |
---|
319 | if( key == SDLK_RMETA) return "RMETA"; |
---|
320 | if( key == SDLK_LMETA) return "LMETA"; |
---|
321 | if( key == SDLK_LSUPER) return "LSUPER"; |
---|
322 | if( key == SDLK_RSUPER) return "RSUPER"; |
---|
323 | if( key == SDLK_MODE) return "MODE"; |
---|
324 | if( key == SDLK_HELP) return "HELP"; |
---|
325 | if( key == SDLK_PRINT) return "PRINT"; |
---|
326 | if( key == SDLK_SYSREQ) return "SYSREQ"; |
---|
327 | if( key == SDLK_BREAK) return "BREAK"; |
---|
328 | if( key == SDLK_MENU) return "MENU"; |
---|
329 | if( key == SDLK_POWER) return "POWER"; |
---|
330 | if( key == SDLK_EURO) return "EURO"; |
---|
331 | return "UNKNOWN"; |
---|
332 | } |
---|