src/video/windows/SDL_windowsevents.c
changeset 6925 59fedfb8faaf
parent 6922 91d157d9f283
child 6929 7fa90e780e2d
equal deleted inserted replaced
6924:5be9b933146a 6925:59fedfb8faaf
    62 #endif
    62 #endif
    63 #ifndef WM_TOUCH
    63 #ifndef WM_TOUCH
    64 #define WM_TOUCH 0x0240
    64 #define WM_TOUCH 0x0240
    65 #endif
    65 #endif
    66 
    66 
    67 
       
    68 static WPARAM
       
    69 RemapVKEY(WPARAM wParam, LPARAM lParam)
       
    70 {
       
    71     int i;
       
    72     BYTE scancode = (BYTE) ((lParam >> 16) & 0xFF);
       
    73 
       
    74     /* Windows remaps alphabetic keys based on current layout.
       
    75        We try to provide USB scancodes, so undo this mapping.
       
    76      */
       
    77     if (wParam >= 'A' && wParam <= 'Z') {
       
    78         if (scancode != alpha_scancodes[wParam - 'A']) {
       
    79             for (i = 0; i < SDL_arraysize(alpha_scancodes); ++i) {
       
    80                 if (scancode == alpha_scancodes[i]) {
       
    81                     wParam = 'A' + i;
       
    82                     break;
       
    83                 }
       
    84             }
       
    85         }
       
    86     }
       
    87 
       
    88     /* Keypad keys are a little trickier, we always scan for them.
       
    89        Keypad arrow keys have the same scancode as normal arrow keys,
       
    90        except they don't have the extended bit (0x1000000) set.
       
    91      */
       
    92     if (!(lParam & 0x1000000)) {
       
    93         if (wParam == VK_DELETE) {
       
    94             wParam = VK_DECIMAL;
       
    95         } else {
       
    96             for (i = 0; i < SDL_arraysize(keypad_scancodes); ++i) {
       
    97                 if (scancode == keypad_scancodes[i]) {
       
    98                     wParam = VK_NUMPAD0 + i;
       
    99                     break;
       
   100                 }
       
   101             }
       
   102         }
       
   103     }
       
   104 
       
   105     return wParam;
       
   106 }
       
   107 
    67 
   108 static SDL_Scancode 
    68 static SDL_Scancode 
   109 WindowsScanCodeToSDLScanCode( int lParam, int wParam, const SDL_Scancode *key_map )
    69 WindowsScanCodeToSDLScanCode( int lParam, int wParam, const SDL_Scancode *key_map )
   110 {
    70 {
   111 	SDL_Scancode code;
    71 	SDL_Scancode code;
   429 #endif /* WM_MOUSELEAVE */
   389 #endif /* WM_MOUSELEAVE */
   430 
   390 
   431     case WM_SYSKEYDOWN:
   391     case WM_SYSKEYDOWN:
   432     case WM_KEYDOWN:
   392     case WM_KEYDOWN:
   433         {
   393         {
   434 			SDL_Scancode code;
   394 			SDL_Scancode code =  WindowsScanCodeToSDLScanCode( lParam, wParam, data->videodata->key_layout );
   435             wParam = RemapVKEY(wParam, lParam);
       
   436             switch (wParam) {
       
   437             case VK_CONTROL:
       
   438                 if (lParam & EXTENDED_KEYMASK)
       
   439                     wParam = VK_RCONTROL;
       
   440                 else
       
   441                     wParam = VK_LCONTROL;
       
   442                 break;
       
   443             case VK_SHIFT:
       
   444                 /* EXTENDED trick doesn't work here */
       
   445                 {
       
   446                     Uint8 *state = SDL_GetKeyboardState(NULL);
       
   447                     if (state[SDL_SCANCODE_LSHIFT] == SDL_RELEASED
       
   448                         && (GetKeyState(VK_LSHIFT) & 0x8000)) {
       
   449                         wParam = VK_LSHIFT;
       
   450                     } else if (state[SDL_SCANCODE_RSHIFT] == SDL_RELEASED
       
   451                                && (GetKeyState(VK_RSHIFT) & 0x8000)) {
       
   452                         wParam = VK_RSHIFT;
       
   453                     } else {
       
   454                         /* Probably a key repeat */
       
   455                         wParam = 256;
       
   456                     }
       
   457                 }
       
   458                 break;
       
   459             case VK_MENU:
       
   460                 if (lParam & EXTENDED_KEYMASK)
       
   461                     wParam = VK_RMENU;
       
   462                 else
       
   463                     wParam = VK_LMENU;
       
   464                 break;
       
   465             case VK_RETURN:
       
   466                 if (lParam & EXTENDED_KEYMASK)
       
   467                     wParam = VK_ENTER;
       
   468                 break;
       
   469             }
       
   470 			code =  WindowsScanCodeToSDLScanCode( lParam, wParam, data->videodata->key_layout );
       
   471 			if ( code != SDL_SCANCODE_UNKNOWN ) {
   395 			if ( code != SDL_SCANCODE_UNKNOWN ) {
   472                 SDL_SendKeyboardKey(SDL_PRESSED, code );
   396                 SDL_SendKeyboardKey(SDL_PRESSED, code );
   473             }
   397             }
   474         }
   398         }
   475         returnCode = 0;
   399         returnCode = 0;
   476         break;
   400         break;
   477 
   401 
   478     case WM_SYSKEYUP:
   402     case WM_SYSKEYUP:
   479     case WM_KEYUP:
   403     case WM_KEYUP:
   480         {
   404         {
   481 			SDL_Scancode code;
   405 			SDL_Scancode code =  WindowsScanCodeToSDLScanCode( lParam, wParam, data->videodata->key_layout );
   482 			wParam = RemapVKEY(wParam, lParam);
       
   483             switch (wParam) {
       
   484             case VK_CONTROL:
       
   485                 if (lParam & EXTENDED_KEYMASK)
       
   486                     wParam = VK_RCONTROL;
       
   487                 else
       
   488                     wParam = VK_LCONTROL;
       
   489                 break;
       
   490             case VK_SHIFT:
       
   491                 /* EXTENDED trick doesn't work here */
       
   492                 {
       
   493                     Uint8 *state = SDL_GetKeyboardState(NULL);
       
   494                     if (state[SDL_SCANCODE_LSHIFT] == SDL_PRESSED
       
   495                         && !(GetKeyState(VK_LSHIFT) & 0x8000)) {
       
   496                         wParam = VK_LSHIFT;
       
   497                     } else if (state[SDL_SCANCODE_RSHIFT] == SDL_PRESSED
       
   498                                && !(GetKeyState(VK_RSHIFT) & 0x8000)) {
       
   499                         wParam = VK_RSHIFT;
       
   500                     } else {
       
   501                         /* Probably a key repeat */
       
   502                         wParam = 256;
       
   503                     }
       
   504                 }
       
   505                 break;
       
   506             case VK_MENU:
       
   507                 if (lParam & EXTENDED_KEYMASK)
       
   508                     wParam = VK_RMENU;
       
   509                 else
       
   510                     wParam = VK_LMENU;
       
   511                 break;
       
   512             case VK_RETURN:
       
   513                 if (lParam & EXTENDED_KEYMASK)
       
   514                     wParam = VK_ENTER;
       
   515                 break;
       
   516             }
       
   517 
       
   518             /* Windows only reports keyup for print screen */
       
   519 			code =  WindowsScanCodeToSDLScanCode( lParam, wParam, data->videodata->key_layout );
       
   520 			if ( code != SDL_SCANCODE_UNKNOWN ) {
   406 			if ( code != SDL_SCANCODE_UNKNOWN ) {
   521 				if (wParam == VK_SNAPSHOT
   407 				if (wParam == VK_SNAPSHOT
   522 				    && SDL_GetKeyboardState(NULL)[SDL_SCANCODE_PRINTSCREEN] ==
   408 				    && SDL_GetKeyboardState(NULL)[SDL_SCANCODE_PRINTSCREEN] ==
   523 				    SDL_RELEASED) {
   409 				    SDL_RELEASED) {
   524 				    SDL_SendKeyboardKey(SDL_PRESSED,
   410 				    SDL_SendKeyboardKey(SDL_PRESSED,