prefer virtual keycodes over scancodes for extended keys
authorouned <michael@losert.org>
Sat, 03 Jun 2017 09:13:08 +0200
changeset 1124133802c660fa0
parent 11240 1f6105d09344
child 11242 70ae86f64702
prefer virtual keycodes over scancodes for extended keys
src/video/windows/SDL_windowsevents.c
     1.1 --- a/src/video/windows/SDL_windowsevents.c	Sat Aug 12 12:34:09 2017 -0700
     1.2 +++ b/src/video/windows/SDL_windowsevents.c	Sat Jun 03 09:13:08 2017 +0200
     1.3 @@ -82,6 +82,64 @@
     1.4  #endif
     1.5  
     1.6  static SDL_Scancode
     1.7 +VKeytoScancode(WPARAM vkey)
     1.8 +{
     1.9 +    switch (vkey) {
    1.10 +    case VK_CLEAR: return SDL_SCANCODE_CLEAR;
    1.11 +    case VK_MODECHANGE: return SDL_SCANCODE_MODE;
    1.12 +    case VK_SELECT: return SDL_SCANCODE_SELECT;
    1.13 +    case VK_EXECUTE: return SDL_SCANCODE_EXECUTE;
    1.14 +    case VK_HELP: return SDL_SCANCODE_HELP;
    1.15 +    case VK_PAUSE: return SDL_SCANCODE_PAUSE;
    1.16 +    case VK_NUMLOCK: return SDL_SCANCODE_NUMLOCKCLEAR;
    1.17 +
    1.18 +    case VK_F13: return SDL_SCANCODE_F13;
    1.19 +    case VK_F14: return SDL_SCANCODE_F14;
    1.20 +    case VK_F15: return SDL_SCANCODE_F15;
    1.21 +    case VK_F16: return SDL_SCANCODE_F16;
    1.22 +    case VK_F17: return SDL_SCANCODE_F17;
    1.23 +    case VK_F18: return SDL_SCANCODE_F18;
    1.24 +    case VK_F19: return SDL_SCANCODE_F19;
    1.25 +    case VK_F20: return SDL_SCANCODE_F20;
    1.26 +    case VK_F21: return SDL_SCANCODE_F21;
    1.27 +    case VK_F22: return SDL_SCANCODE_F22;
    1.28 +    case VK_F23: return SDL_SCANCODE_F23;
    1.29 +    case VK_F24: return SDL_SCANCODE_F24;
    1.30 +
    1.31 +    case VK_OEM_NEC_EQUAL: return SDL_SCANCODE_KP_EQUALS;
    1.32 +    case VK_BROWSER_BACK: return SDL_SCANCODE_AC_BACK;
    1.33 +    case VK_BROWSER_FORWARD: return SDL_SCANCODE_AC_FORWARD;
    1.34 +    case VK_BROWSER_REFRESH: return SDL_SCANCODE_AC_REFRESH;
    1.35 +    case VK_BROWSER_STOP: return SDL_SCANCODE_AC_STOP;
    1.36 +    case VK_BROWSER_SEARCH: return SDL_SCANCODE_AC_SEARCH;
    1.37 +    case VK_BROWSER_FAVORITES: return SDL_SCANCODE_AC_BOOKMARKS;
    1.38 +    case VK_BROWSER_HOME: return SDL_SCANCODE_AC_HOME;
    1.39 +    case VK_VOLUME_MUTE: return SDL_SCANCODE_AUDIOMUTE;
    1.40 +    case VK_VOLUME_DOWN: return SDL_SCANCODE_VOLUMEDOWN;
    1.41 +    case VK_VOLUME_UP: return SDL_SCANCODE_VOLUMEUP;
    1.42 +
    1.43 +    case VK_MEDIA_NEXT_TRACK: return SDL_SCANCODE_AUDIONEXT;
    1.44 +    case VK_MEDIA_PREV_TRACK: return SDL_SCANCODE_AUDIOPREV;
    1.45 +    case VK_MEDIA_STOP: return SDL_SCANCODE_AUDIOSTOP;
    1.46 +    case VK_MEDIA_PLAY_PAUSE: return SDL_SCANCODE_AUDIOPLAY;
    1.47 +    case VK_LAUNCH_MAIL: return SDL_SCANCODE_MAIL;
    1.48 +    case VK_LAUNCH_MEDIA_SELECT: return SDL_SCANCODE_MEDIASELECT;
    1.49 +
    1.50 +    case VK_OEM_102: return SDL_SCANCODE_NONUSBACKSLASH;
    1.51 +
    1.52 +    case VK_ATTN: return SDL_SCANCODE_SYSREQ;
    1.53 +    case VK_CRSEL: return SDL_SCANCODE_CRSEL;
    1.54 +    case VK_EXSEL: return SDL_SCANCODE_EXSEL;
    1.55 +    case VK_OEM_CLEAR: return SDL_SCANCODE_CLEAR;
    1.56 +
    1.57 +    case VK_LAUNCH_APP1: return SDL_SCANCODE_APP1;
    1.58 +    case VK_LAUNCH_APP2: return SDL_SCANCODE_APP2;
    1.59 +
    1.60 +    default: return SDL_SCANCODE_UNKNOWN;
    1.61 +    }
    1.62 +}
    1.63 +
    1.64 +static SDL_Scancode
    1.65  WindowsScanCodeToSDLScanCode(LPARAM lParam, WPARAM wParam)
    1.66  {
    1.67      SDL_Scancode code;
    1.68 @@ -90,59 +148,7 @@
    1.69  
    1.70      /* 0x45 here to work around both pause and numlock sharing the same scancode, so use the VK key to tell them apart */
    1.71      if (nScanCode == 0 || nScanCode == 0x45) {
    1.72 -        switch(wParam) {
    1.73 -        case VK_CLEAR: return SDL_SCANCODE_CLEAR;
    1.74 -        case VK_MODECHANGE: return SDL_SCANCODE_MODE;
    1.75 -        case VK_SELECT: return SDL_SCANCODE_SELECT;
    1.76 -        case VK_EXECUTE: return SDL_SCANCODE_EXECUTE;
    1.77 -        case VK_HELP: return SDL_SCANCODE_HELP;
    1.78 -        case VK_PAUSE: return SDL_SCANCODE_PAUSE;
    1.79 -        case VK_NUMLOCK: return SDL_SCANCODE_NUMLOCKCLEAR;
    1.80 -
    1.81 -        case VK_F13: return SDL_SCANCODE_F13;
    1.82 -        case VK_F14: return SDL_SCANCODE_F14;
    1.83 -        case VK_F15: return SDL_SCANCODE_F15;
    1.84 -        case VK_F16: return SDL_SCANCODE_F16;
    1.85 -        case VK_F17: return SDL_SCANCODE_F17;
    1.86 -        case VK_F18: return SDL_SCANCODE_F18;
    1.87 -        case VK_F19: return SDL_SCANCODE_F19;
    1.88 -        case VK_F20: return SDL_SCANCODE_F20;
    1.89 -        case VK_F21: return SDL_SCANCODE_F21;
    1.90 -        case VK_F22: return SDL_SCANCODE_F22;
    1.91 -        case VK_F23: return SDL_SCANCODE_F23;
    1.92 -        case VK_F24: return SDL_SCANCODE_F24;
    1.93 -
    1.94 -        case VK_OEM_NEC_EQUAL: return SDL_SCANCODE_KP_EQUALS;
    1.95 -        case VK_BROWSER_BACK: return SDL_SCANCODE_AC_BACK;
    1.96 -        case VK_BROWSER_FORWARD: return SDL_SCANCODE_AC_FORWARD;
    1.97 -        case VK_BROWSER_REFRESH: return SDL_SCANCODE_AC_REFRESH;
    1.98 -        case VK_BROWSER_STOP: return SDL_SCANCODE_AC_STOP;
    1.99 -        case VK_BROWSER_SEARCH: return SDL_SCANCODE_AC_SEARCH;
   1.100 -        case VK_BROWSER_FAVORITES: return SDL_SCANCODE_AC_BOOKMARKS;
   1.101 -        case VK_BROWSER_HOME: return SDL_SCANCODE_AC_HOME;
   1.102 -        case VK_VOLUME_MUTE: return SDL_SCANCODE_AUDIOMUTE;
   1.103 -        case VK_VOLUME_DOWN: return SDL_SCANCODE_VOLUMEDOWN;
   1.104 -        case VK_VOLUME_UP: return SDL_SCANCODE_VOLUMEUP;
   1.105 -
   1.106 -        case VK_MEDIA_NEXT_TRACK: return SDL_SCANCODE_AUDIONEXT;
   1.107 -        case VK_MEDIA_PREV_TRACK: return SDL_SCANCODE_AUDIOPREV;
   1.108 -        case VK_MEDIA_STOP: return SDL_SCANCODE_AUDIOSTOP;
   1.109 -        case VK_MEDIA_PLAY_PAUSE: return SDL_SCANCODE_AUDIOPLAY;
   1.110 -        case VK_LAUNCH_MAIL: return SDL_SCANCODE_MAIL;
   1.111 -        case VK_LAUNCH_MEDIA_SELECT: return SDL_SCANCODE_MEDIASELECT;
   1.112 -
   1.113 -        case VK_OEM_102: return SDL_SCANCODE_NONUSBACKSLASH;
   1.114 -
   1.115 -        case VK_ATTN: return SDL_SCANCODE_SYSREQ;
   1.116 -        case VK_CRSEL: return SDL_SCANCODE_CRSEL;
   1.117 -        case VK_EXSEL: return SDL_SCANCODE_EXSEL;
   1.118 -        case VK_OEM_CLEAR: return SDL_SCANCODE_CLEAR;
   1.119 -
   1.120 -        case VK_LAUNCH_APP1: return SDL_SCANCODE_APP1;
   1.121 -        case VK_LAUNCH_APP2: return SDL_SCANCODE_APP2;
   1.122 -
   1.123 -        default: return SDL_SCANCODE_UNKNOWN;
   1.124 -        }
   1.125 +        return VKeytoScancode(wParam);
   1.126      }
   1.127  
   1.128      if (nScanCode > 127)
   1.129 @@ -178,20 +184,26 @@
   1.130          default:
   1.131              break;
   1.132          }
   1.133 +        /* prefer virtual keycodes over scancodes for extended keys */
   1.134      } else {
   1.135 -        switch (code) {
   1.136 -        case SDL_SCANCODE_RETURN:
   1.137 -            return SDL_SCANCODE_KP_ENTER;
   1.138 -        case SDL_SCANCODE_LALT:
   1.139 -            return SDL_SCANCODE_RALT;
   1.140 -        case SDL_SCANCODE_LCTRL:
   1.141 -            return SDL_SCANCODE_RCTRL;
   1.142 -        case SDL_SCANCODE_SLASH:
   1.143 -            return SDL_SCANCODE_KP_DIVIDE;
   1.144 -        case SDL_SCANCODE_CAPSLOCK:
   1.145 -            return SDL_SCANCODE_KP_PLUS;
   1.146 -        default:
   1.147 -            break;
   1.148 +        SDL_Scancode vc = VKeytoScancode(wParam);
   1.149 +        if (vc != SDL_SCANCODE_UNKNOWN) {
   1.150 +            code = vc;
   1.151 +        } else {
   1.152 +            switch (code) {
   1.153 +            case SDL_SCANCODE_RETURN:
   1.154 +                return SDL_SCANCODE_KP_ENTER;
   1.155 +            case SDL_SCANCODE_LALT:
   1.156 +                return SDL_SCANCODE_RALT;
   1.157 +            case SDL_SCANCODE_LCTRL:
   1.158 +                return SDL_SCANCODE_RCTRL;
   1.159 +            case SDL_SCANCODE_SLASH:
   1.160 +                return SDL_SCANCODE_KP_DIVIDE;
   1.161 +            case SDL_SCANCODE_CAPSLOCK:
   1.162 +                return SDL_SCANCODE_KP_PLUS;
   1.163 +            default:
   1.164 +                break;
   1.165 +            }
   1.166          }
   1.167      }
   1.168