21 [[nodiscard]]
constexpr bool operator()(
const P& x,
const P& y)
const {
26 [[nodiscard]]
bool operator()(
const P& x, string_view y)
const {
28 return cmp(x.
first, y);
30 [[nodiscard]]
bool operator()(string_view x,
const P& y)
const {
32 return cmp(x, y.
first);
39static_assert(_MSC_VER >= 1923,
"visual studio version too old");
41static constexpr auto getSortedKeys()
43 auto keys = std::array{
328static constexpr auto keys = getSortedKeys();
332 auto result =
static_cast<KeyCode>(0);
333 string_view::size_type lastPos = 0;
334 while (lastPos != string_view::npos) {
335 auto pos = name.substr(lastPos).find_first_of(
",+/");
336 auto part = (pos != string_view::npos)
337 ? name.substr(lastPos, pos)
338 : name.substr(lastPos);
349 result =
static_cast<KeyCode>(result | partCode);
350 lastPos = (pos != string_view::npos)
357std::pair<KeyCode, KeyCode>
getCodes(SDL_Keycode sdlKeyCode, Uint16 mod, SDL_Scancode sdlScanCode,
bool release)
360 switch (sdlKeyCode) {
362 case SDLK_TAB:
return K_TAB;
363 case SDLK_CLEAR:
return K_CLEAR;
365 case SDLK_PAUSE:
return K_PAUSE;
367 case SDLK_SPACE:
return K_SPACE;
370 case SDLK_HASH:
return K_HASH;
373 case SDLK_QUOTE:
return K_QUOTE;
377 case SDLK_PLUS:
return K_PLUS;
378 case SDLK_COMMA:
return K_COMMA;
379 case SDLK_MINUS:
return K_MINUS;
381 case SDLK_SLASH:
return K_SLASH;
382 case SDLK_0:
return K_0;
383 case SDLK_1:
return K_1;
384 case SDLK_2:
return K_2;
385 case SDLK_3:
return K_3;
386 case SDLK_4:
return K_4;
387 case SDLK_5:
return K_5;
388 case SDLK_6:
return K_6;
389 case SDLK_7:
return K_7;
390 case SDLK_8:
return K_8;
391 case SDLK_9:
return K_9;
392 case SDLK_COLON:
return K_COLON;
394 case SDLK_LESS:
return K_LESS;
398 case SDLK_AT:
return K_AT;
403 case SDLK_CARET:
return K_CARET;
406 case SDLK_a:
return K_A;
407 case SDLK_b:
return K_B;
408 case SDLK_c:
return K_C;
409 case SDLK_d:
return K_D;
410 case SDLK_e:
return K_E;
411 case SDLK_f:
return K_F;
412 case SDLK_g:
return K_G;
413 case SDLK_h:
return K_H;
414 case SDLK_i:
return K_I;
415 case SDLK_j:
return K_J;
416 case SDLK_k:
return K_K;
417 case SDLK_l:
return K_L;
418 case SDLK_m:
return K_M;
419 case SDLK_n:
return K_N;
420 case SDLK_o:
return K_O;
421 case SDLK_p:
return K_P;
422 case SDLK_q:
return K_Q;
423 case SDLK_r:
return K_R;
424 case SDLK_s:
return K_S;
425 case SDLK_t:
return K_T;
426 case SDLK_u:
return K_U;
427 case SDLK_v:
return K_V;
428 case SDLK_w:
return K_W;
429 case SDLK_x:
return K_X;
430 case SDLK_y:
return K_Y;
431 case SDLK_z:
return K_Z;
435 case SDLK_KP_0:
return K_KP0;
436 case SDLK_KP_1:
return K_KP1;
437 case SDLK_KP_2:
return K_KP2;
438 case SDLK_KP_3:
return K_KP3;
439 case SDLK_KP_4:
return K_KP4;
440 case SDLK_KP_5:
return K_KP5;
441 case SDLK_KP_6:
return K_KP6;
442 case SDLK_KP_7:
return K_KP7;
443 case SDLK_KP_8:
return K_KP8;
444 case SDLK_KP_9:
return K_KP9;
454 case SDLK_UP:
return K_UP;
455 case SDLK_DOWN:
return K_DOWN;
456 case SDLK_RIGHT:
return K_RIGHT;
457 case SDLK_LEFT:
return K_LEFT;
459 case SDLK_HOME:
return K_HOME;
460 case SDLK_END:
return K_END;
465 case SDLK_F1:
return K_F1;
466 case SDLK_F2:
return K_F2;
467 case SDLK_F3:
return K_F3;
468 case SDLK_F4:
return K_F4;
469 case SDLK_F5:
return K_F5;
470 case SDLK_F6:
return K_F6;
471 case SDLK_F7:
return K_F7;
472 case SDLK_F8:
return K_F8;
473 case SDLK_F9:
return K_F9;
474 case SDLK_F10:
return K_F10;
475 case SDLK_F11:
return K_F11;
476 case SDLK_F12:
return K_F12;
477 case SDLK_F13:
return K_F13;
478 case SDLK_F14:
return K_F14;
479 case SDLK_F15:
return K_F15;
480 case SDLK_F16:
return K_F16;
481 case SDLK_F17:
return K_F17;
482 case SDLK_F18:
return K_F18;
483 case SDLK_F19:
return K_F19;
484 case SDLK_F20:
return K_F20;
485 case SDLK_F21:
return K_F21;
486 case SDLK_F22:
return K_F22;
487 case SDLK_F23:
return K_F23;
488 case SDLK_F24:
return K_F24;
491 case SDLK_NUMLOCKCLEAR:
return K_NUMLOCK;
496 case SDLK_RCTRL:
return K_RCTRL;
497 case SDLK_LCTRL:
return K_LCTRL;
498 case SDLK_RALT:
return K_RALT;
499 case SDLK_LALT:
return K_LALT;
504 case SDLK_MODE:
return K_MODE;
508 case SDLK_HELP:
return K_HELP;
509 case SDLK_PRINTSCREEN:
return K_PRINT;
512 case SDLK_APPLICATION:
return K_MENU;
513 case SDLK_MENU:
return K_MENU;
514 case SDLK_POWER:
return K_POWER;
516 case SDLK_UNDO:
return K_UNDO;
519 case SDLK_AC_BACK:
return K_BACK;
526 switch (sdlScanCode) {
528 case SDL_SCANCODE_TAB:
return K_TAB;
529 case SDL_SCANCODE_CLEAR:
return K_CLEAR;
530 case SDL_SCANCODE_RETURN:
return K_RETURN;
531 case SDL_SCANCODE_PAUSE:
return K_PAUSE;
532 case SDL_SCANCODE_ESCAPE:
return K_ESCAPE;
533 case SDL_SCANCODE_SPACE:
return K_SPACE;
534 case SDL_SCANCODE_APOSTROPHE:
return K_QUOTE;
535 case SDL_SCANCODE_COMMA:
return K_COMMA;
536 case SDL_SCANCODE_MINUS:
return K_MINUS;
537 case SDL_SCANCODE_PERIOD:
return K_PERIOD;
538 case SDL_SCANCODE_SLASH:
return K_SLASH;
539 case SDL_SCANCODE_0:
return K_0;
540 case SDL_SCANCODE_1:
return K_1;
541 case SDL_SCANCODE_2:
return K_2;
542 case SDL_SCANCODE_3:
return K_3;
543 case SDL_SCANCODE_4:
return K_4;
544 case SDL_SCANCODE_5:
return K_5;
545 case SDL_SCANCODE_6:
return K_6;
546 case SDL_SCANCODE_7:
return K_7;
547 case SDL_SCANCODE_8:
return K_8;
548 case SDL_SCANCODE_9:
return K_9;
550 case SDL_SCANCODE_EQUALS:
return K_EQUALS;
556 case SDL_SCANCODE_A:
return K_A;
557 case SDL_SCANCODE_B:
return K_B;
558 case SDL_SCANCODE_C:
return K_C;
559 case SDL_SCANCODE_D:
return K_D;
560 case SDL_SCANCODE_E:
return K_E;
561 case SDL_SCANCODE_F:
return K_F;
562 case SDL_SCANCODE_G:
return K_G;
563 case SDL_SCANCODE_H:
return K_H;
564 case SDL_SCANCODE_I:
return K_I;
565 case SDL_SCANCODE_J:
return K_J;
566 case SDL_SCANCODE_K:
return K_K;
567 case SDL_SCANCODE_L:
return K_L;
568 case SDL_SCANCODE_M:
return K_M;
569 case SDL_SCANCODE_N:
return K_N;
570 case SDL_SCANCODE_O:
return K_O;
571 case SDL_SCANCODE_P:
return K_P;
572 case SDL_SCANCODE_Q:
return K_Q;
573 case SDL_SCANCODE_R:
return K_R;
574 case SDL_SCANCODE_S:
return K_S;
575 case SDL_SCANCODE_T:
return K_T;
576 case SDL_SCANCODE_U:
return K_U;
577 case SDL_SCANCODE_V:
return K_V;
578 case SDL_SCANCODE_W:
return K_W;
579 case SDL_SCANCODE_X:
return K_X;
580 case SDL_SCANCODE_Y:
return K_Y;
581 case SDL_SCANCODE_Z:
return K_Z;
582 case SDL_SCANCODE_DELETE:
return K_DELETE;
585 case SDL_SCANCODE_KP_0:
return K_KP0;
586 case SDL_SCANCODE_KP_1:
return K_KP1;
587 case SDL_SCANCODE_KP_2:
return K_KP2;
588 case SDL_SCANCODE_KP_3:
return K_KP3;
589 case SDL_SCANCODE_KP_4:
return K_KP4;
590 case SDL_SCANCODE_KP_5:
return K_KP5;
591 case SDL_SCANCODE_KP_6:
return K_KP6;
592 case SDL_SCANCODE_KP_7:
return K_KP7;
593 case SDL_SCANCODE_KP_8:
return K_KP8;
594 case SDL_SCANCODE_KP_9:
return K_KP9;
598 case SDL_SCANCODE_KP_MINUS:
return K_KP_MINUS;
599 case SDL_SCANCODE_KP_PLUS:
return K_KP_PLUS;
600 case SDL_SCANCODE_KP_ENTER:
return K_KP_ENTER;
604 case SDL_SCANCODE_UP:
return K_UP;
605 case SDL_SCANCODE_DOWN:
return K_DOWN;
606 case SDL_SCANCODE_RIGHT:
return K_RIGHT;
607 case SDL_SCANCODE_LEFT:
return K_LEFT;
608 case SDL_SCANCODE_INSERT:
return K_INSERT;
609 case SDL_SCANCODE_HOME:
return K_HOME;
610 case SDL_SCANCODE_END:
return K_END;
611 case SDL_SCANCODE_PAGEUP:
return K_PAGEUP;
612 case SDL_SCANCODE_PAGEDOWN:
return K_PAGEDOWN;
615 case SDL_SCANCODE_F1:
return K_F1;
616 case SDL_SCANCODE_F2:
return K_F2;
617 case SDL_SCANCODE_F3:
return K_F3;
618 case SDL_SCANCODE_F4:
return K_F4;
619 case SDL_SCANCODE_F5:
return K_F5;
620 case SDL_SCANCODE_F6:
return K_F6;
621 case SDL_SCANCODE_F7:
return K_F7;
622 case SDL_SCANCODE_F8:
return K_F8;
623 case SDL_SCANCODE_F9:
return K_F9;
624 case SDL_SCANCODE_F10:
return K_F10;
625 case SDL_SCANCODE_F11:
return K_F11;
626 case SDL_SCANCODE_F12:
return K_F12;
627 case SDL_SCANCODE_F13:
return K_F13;
628 case SDL_SCANCODE_F14:
return K_F14;
629 case SDL_SCANCODE_F15:
return K_F15;
630 case SDL_SCANCODE_F16:
return K_F16;
631 case SDL_SCANCODE_F17:
return K_F17;
632 case SDL_SCANCODE_F18:
return K_F18;
633 case SDL_SCANCODE_F19:
return K_F19;
634 case SDL_SCANCODE_F20:
return K_F20;
635 case SDL_SCANCODE_F21:
return K_F21;
636 case SDL_SCANCODE_F22:
return K_F22;
637 case SDL_SCANCODE_F23:
return K_F23;
638 case SDL_SCANCODE_F24:
return K_F24;
641 case SDL_SCANCODE_NUMLOCKCLEAR:
return K_NUMLOCK;
642 case SDL_SCANCODE_CAPSLOCK:
return K_CAPSLOCK;
644 case SDL_SCANCODE_RSHIFT:
return K_RSHIFT;
645 case SDL_SCANCODE_LSHIFT:
return K_LSHIFT;
646 case SDL_SCANCODE_RCTRL:
return K_RCTRL;
647 case SDL_SCANCODE_LCTRL:
return K_LCTRL;
648 case SDL_SCANCODE_RALT:
return K_RALT;
649 case SDL_SCANCODE_LALT:
return K_LALT;
650 case SDL_SCANCODE_LGUI:
return K_LSUPER;
651 case SDL_SCANCODE_RGUI:
return K_RSUPER;
652 case SDL_SCANCODE_MODE:
return K_MODE;
655 case SDL_SCANCODE_HELP:
return K_HELP;
656 case SDL_SCANCODE_PRINTSCREEN:
return K_PRINT;
657 case SDL_SCANCODE_SYSREQ:
return K_SYSREQ;
658 case SDL_SCANCODE_APPLICATION:
return K_MENU;
659 case SDL_SCANCODE_MENU:
return K_MENU;
660 case SDL_SCANCODE_POWER:
return K_POWER;
661 case SDL_SCANCODE_UNDO:
return K_UNDO;
664 case SDL_SCANCODE_AC_BACK:
return K_BACK;
676 switch (sdlScanCode) {
702 if (mod & KMOD_CTRL) {
706 if (mod & KMOD_SHIFT) {
710 if (mod & KMOD_ALT) {
714 if (mod & KMOD_GUI) {
718 if (mod & KMOD_MODE) {
733 for (
const auto& [name, code] : keys) {
734 if (code == (keyCode &
K_MASK)) {
739 if (result.empty()) {
758 result +=
",RELEASE";
KeyCode combine(KeyCode key, KeyCode modifier)
Convenience method to create key combinations (hides ugly casts).
KeyCode
Constants that identify keys and key modifiers.
std::pair< KeyCode, KeyCode > getCodes(SDL_Keycode sdlKeyCode, Uint16 mod, SDL_Scancode sdlScanCode, bool release)
Translate SDL_Keycode/SDL_Scancode into openMSX key/scan Keycode's.
KeyCode getCode(string_view name)
Translate key name to key code.
std::string getName(KeyCode keyCode)
Translate key code to key name.
constexpr void sort(RandomAccessRange &&range)
auto * binary_find(ForwardRange &&range, const T &value, Compare comp={}, Proj proj={})
bool operator()(const P &x, string_view y) const
constexpr bool operator()(const P &x, const P &y) const
bool operator()(string_view x, const P &y) const
constexpr P(string_view s, KeyCode k)