MCPcopy Create free account
hub / github.com/crawl/crawl / _name_to_keycode

Function _name_to_keycode

crawl-ref/source/macro.cc:260–365  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

258}
259
260static int _name_to_keycode(string s)
261{
262 // brute-force partial inversion of keycode_to_name. This could probably
263 // be done much more elegantly via a map or similar..
264 // Does not handle modifier keys besides ctrl (TODO)
265 const string lower = lowercase(s);
266 if (s[0] == '^' && s.size() == 2)
267 {
268 // ^A = 1, etc.
269 return 1 + toupper_safe(s[1]) - 'A';
270 }
271 if (starts_with(lower, "np") && s.size() == 3)
272 {
273 switch (s[2])
274 {
275 case '0': return CK_NUMPAD_0;
276 case '1': return CK_NUMPAD_1;
277 case '2': return CK_NUMPAD_2;
278 case '3': return CK_NUMPAD_3;
279 case '4': return CK_NUMPAD_4;
280 case '5': return CK_NUMPAD_5;
281 case '6': return CK_NUMPAD_6;
282 case '7': return CK_NUMPAD_7;
283 case '8': return CK_NUMPAD_8;
284 case '9': return CK_NUMPAD_9;
285 case '*': return CK_NUMPAD_MULTIPLY;
286 case '+': return CK_NUMPAD_ADD;
287 case '-': return CK_NUMPAD_SUBTRACT;
288 case '.': return CK_NUMPAD_DECIMAL;
289 case '/': return CK_NUMPAD_DIVIDE;
290 case '=': return CK_NUMPAD_EQUALS;
291 default:
292 return CK_NO_KEY;
293 }
294 }
295 else if (lower == "npenter")
296 return CK_NUMPAD_ENTER;
297 else if (starts_with(lowercase(s), "f") && s.size() == 2)
298 {
299 switch (s[1])
300 {
301 case '0': return CK_F0;
302 case '1': return CK_F1;
303 case '2': return CK_F2;
304 case '3': return CK_F3;
305 case '4': return CK_F4;
306 case '5': return CK_F5;
307 case '6': return CK_F6;
308 case '7': return CK_F7;
309 case '8': return CK_F8;
310 case '9': return CK_F9;
311 default:
312 return CK_NO_KEY;
313 }
314 }
315 else if (starts_with(lower, "f1") && s.size() == 3)
316 {
317 switch (s[1])

Callers 1

read_key_codeFunction · 0.85

Calls 3

toupper_safeFunction · 0.85
starts_withFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected