sdl2
authorJørgen P. Tjernø <jorgen@valvesoftware.com>
Mon, 25 Feb 2013 16:52:51 -0800
changeset 692559fedfb8faaf
parent 6924 5be9b933146a
child 6926 166712f45009
sdl2
- more scancode goodness, removing now dead wparam translation code
- add scancode for SDL_SCANCODE_NONUSBACKSLASH
- don't translate sdl key values for numeric and grave key

CR: SamL
src/events/scancodes_windows.h
src/video/windows/SDL_windowsevents.c
src/video/windows/SDL_windowskeyboard.c
     1.1 --- a/src/events/scancodes_windows.h	Mon Feb 25 16:52:50 2013 -0800
     1.2 +++ b/src/events/scancodes_windows.h	Mon Feb 25 16:52:51 2013 -0800
     1.3 @@ -29,31 +29,31 @@
     1.4  // Google for 'Keyboard Scan Code Specification'
     1.5  static const SDL_Scancode windows_scancode_table[] = 
     1.6  { 
     1.7 -	//	0						1							2						3						4							5							6						7 
     1.8 -	//	8						9							A						B						C							D							E						F 
     1.9 -	SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_ESCAPE,		SDL_SCANCODE_1,			SDL_SCANCODE_2,				SDL_SCANCODE_3,			SDL_SCANCODE_4,				SDL_SCANCODE_5,			SDL_SCANCODE_6,			// 0
    1.10 -	SDL_SCANCODE_7,				SDL_SCANCODE_8,				SDL_SCANCODE_9,			SDL_SCANCODE_0,				SDL_SCANCODE_MINUS,		SDL_SCANCODE_EQUALS,		SDL_SCANCODE_BACKSPACE,	SDL_SCANCODE_TAB,		// 0 
    1.11 +	//	0						1							2							3							4						5							6							7 
    1.12 +	//	8						9							A							B							C						D							E							F 
    1.13 +	SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_ESCAPE,		SDL_SCANCODE_1,				SDL_SCANCODE_2,				SDL_SCANCODE_3,			SDL_SCANCODE_4,				SDL_SCANCODE_5,				SDL_SCANCODE_6,			// 0
    1.14 +	SDL_SCANCODE_7,				SDL_SCANCODE_8,				SDL_SCANCODE_9,				SDL_SCANCODE_0,				SDL_SCANCODE_MINUS,		SDL_SCANCODE_EQUALS,		SDL_SCANCODE_BACKSPACE,		SDL_SCANCODE_TAB,		// 0 
    1.15  
    1.16 -	SDL_SCANCODE_Q,				SDL_SCANCODE_W,			SDL_SCANCODE_E,				SDL_SCANCODE_R,				SDL_SCANCODE_T,			SDL_SCANCODE_Y,				SDL_SCANCODE_U,			SDL_SCANCODE_I,			// 1
    1.17 -	SDL_SCANCODE_O,				SDL_SCANCODE_P,			SDL_SCANCODE_LEFTBRACKET,	SDL_SCANCODE_RIGHTBRACKET,	SDL_SCANCODE_RETURN,	SDL_SCANCODE_LCTRL,			SDL_SCANCODE_A,			SDL_SCANCODE_S,			// 1 
    1.18 +	SDL_SCANCODE_Q,				SDL_SCANCODE_W,				SDL_SCANCODE_E,				SDL_SCANCODE_R,				SDL_SCANCODE_T,			SDL_SCANCODE_Y,				SDL_SCANCODE_U,				SDL_SCANCODE_I,			// 1
    1.19 +	SDL_SCANCODE_O,				SDL_SCANCODE_P,				SDL_SCANCODE_LEFTBRACKET,	SDL_SCANCODE_RIGHTBRACKET,	SDL_SCANCODE_RETURN,	SDL_SCANCODE_LCTRL,			SDL_SCANCODE_A,				SDL_SCANCODE_S,			// 1 
    1.20  
    1.21 -	SDL_SCANCODE_D,				SDL_SCANCODE_F,			SDL_SCANCODE_G,				SDL_SCANCODE_H,				SDL_SCANCODE_J,			SDL_SCANCODE_K,				SDL_SCANCODE_L,			SDL_SCANCODE_SEMICOLON,	// 2 
    1.22 -	SDL_SCANCODE_APOSTROPHE,	SDL_SCANCODE_GRAVE,		SDL_SCANCODE_LSHIFT,		SDL_SCANCODE_BACKSLASH,		SDL_SCANCODE_Z,			SDL_SCANCODE_X,				SDL_SCANCODE_C,			SDL_SCANCODE_V,			// 2 
    1.23 +	SDL_SCANCODE_D,				SDL_SCANCODE_F,				SDL_SCANCODE_G,				SDL_SCANCODE_H,				SDL_SCANCODE_J,			SDL_SCANCODE_K,				SDL_SCANCODE_L,				SDL_SCANCODE_SEMICOLON,	// 2 
    1.24 +	SDL_SCANCODE_APOSTROPHE,	SDL_SCANCODE_GRAVE,			SDL_SCANCODE_LSHIFT,		SDL_SCANCODE_BACKSLASH,		SDL_SCANCODE_Z,			SDL_SCANCODE_X,				SDL_SCANCODE_C,				SDL_SCANCODE_V,			// 2 
    1.25  
    1.26 -	SDL_SCANCODE_B,				SDL_SCANCODE_N,			SDL_SCANCODE_M,				SDL_SCANCODE_COMMA,			SDL_SCANCODE_PERIOD,	SDL_SCANCODE_SLASH,			SDL_SCANCODE_RSHIFT,	SDL_SCANCODE_PRINTSCREEN,// 3
    1.27 -	SDL_SCANCODE_LALT,			SDL_SCANCODE_SPACE,		SDL_SCANCODE_CAPSLOCK,		SDL_SCANCODE_F1,			SDL_SCANCODE_F2,		SDL_SCANCODE_F3,			SDL_SCANCODE_F4,		SDL_SCANCODE_F5,			// 3 
    1.28 +	SDL_SCANCODE_B,				SDL_SCANCODE_N,				SDL_SCANCODE_M,				SDL_SCANCODE_COMMA,			SDL_SCANCODE_PERIOD,	SDL_SCANCODE_SLASH,			SDL_SCANCODE_RSHIFT,		SDL_SCANCODE_PRINTSCREEN,// 3
    1.29 +	SDL_SCANCODE_LALT,			SDL_SCANCODE_SPACE,			SDL_SCANCODE_CAPSLOCK,		SDL_SCANCODE_F1,			SDL_SCANCODE_F2,		SDL_SCANCODE_F3,			SDL_SCANCODE_F4,			SDL_SCANCODE_F5,			// 3 
    1.30  
    1.31 -	SDL_SCANCODE_F6,			SDL_SCANCODE_F7,		SDL_SCANCODE_F8,			SDL_SCANCODE_F9,			SDL_SCANCODE_F10,		SDL_SCANCODE_NUMLOCKCLEAR,	SDL_SCANCODE_SCROLLLOCK,SDL_SCANCODE_HOME,		// 4
    1.32 -	SDL_SCANCODE_UP,			SDL_SCANCODE_PAGEUP,	SDL_SCANCODE_KP_MINUS,		SDL_SCANCODE_LEFT,			SDL_SCANCODE_KP_5,		SDL_SCANCODE_RIGHT,			SDL_SCANCODE_KP_PLUS,	SDL_SCANCODE_END,		// 4 
    1.33 +	SDL_SCANCODE_F6,			SDL_SCANCODE_F7,			SDL_SCANCODE_F8,			SDL_SCANCODE_F9,			SDL_SCANCODE_F10,		SDL_SCANCODE_NUMLOCKCLEAR,	SDL_SCANCODE_SCROLLLOCK,	SDL_SCANCODE_HOME,		// 4
    1.34 +	SDL_SCANCODE_UP,			SDL_SCANCODE_PAGEUP,		SDL_SCANCODE_KP_MINUS,		SDL_SCANCODE_LEFT,			SDL_SCANCODE_KP_5,		SDL_SCANCODE_RIGHT,			SDL_SCANCODE_KP_PLUS,		SDL_SCANCODE_END,		// 4 
    1.35  
    1.36 -	SDL_SCANCODE_DOWN,			SDL_SCANCODE_PAGEDOWN,	SDL_SCANCODE_INSERT,		SDL_SCANCODE_DELETE,		SDL_SCANCODE_UNKNOWN,	SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,	SDL_SCANCODE_F11,		// 5
    1.37 -	SDL_SCANCODE_F12,			SDL_SCANCODE_PAUSE,		SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_LGUI,			SDL_SCANCODE_RGUI,		SDL_SCANCODE_APPLICATION,		SDL_SCANCODE_UNKNOWN,	SDL_SCANCODE_UNKNOWN,		// 5
    1.38 +	SDL_SCANCODE_DOWN,			SDL_SCANCODE_PAGEDOWN,		SDL_SCANCODE_INSERT,		SDL_SCANCODE_DELETE,		SDL_SCANCODE_UNKNOWN,	SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_NONUSBACKSLASH,SDL_SCANCODE_F11,		// 5
    1.39 +	SDL_SCANCODE_F12,			SDL_SCANCODE_PAUSE,			SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_LGUI,			SDL_SCANCODE_RGUI,		SDL_SCANCODE_APPLICATION,	SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,		// 5
    1.40  
    1.41 -	SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,	SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,	SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,	SDL_SCANCODE_UNKNOWN,		// 6
    1.42 -	SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,	SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,	SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,	SDL_SCANCODE_UNKNOWN,		// 6 
    1.43 +	SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,	SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,		// 6
    1.44 +	SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,	SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,		// 6 
    1.45  	
    1.46 -	SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,	SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,	SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,	SDL_SCANCODE_UNKNOWN,		// 7
    1.47 -	SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,	SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,	SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,	SDL_SCANCODE_UNKNOWN		// 7 
    1.48 +	SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,	SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,		// 7
    1.49 +	SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,	SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN		// 7 
    1.50  };
    1.51  
    1.52  /* *INDENT-ON* */
     2.1 --- a/src/video/windows/SDL_windowsevents.c	Mon Feb 25 16:52:50 2013 -0800
     2.2 +++ b/src/video/windows/SDL_windowsevents.c	Mon Feb 25 16:52:51 2013 -0800
     2.3 @@ -65,46 +65,6 @@
     2.4  #endif
     2.5  
     2.6  
     2.7 -static WPARAM
     2.8 -RemapVKEY(WPARAM wParam, LPARAM lParam)
     2.9 -{
    2.10 -    int i;
    2.11 -    BYTE scancode = (BYTE) ((lParam >> 16) & 0xFF);
    2.12 -
    2.13 -    /* Windows remaps alphabetic keys based on current layout.
    2.14 -       We try to provide USB scancodes, so undo this mapping.
    2.15 -     */
    2.16 -    if (wParam >= 'A' && wParam <= 'Z') {
    2.17 -        if (scancode != alpha_scancodes[wParam - 'A']) {
    2.18 -            for (i = 0; i < SDL_arraysize(alpha_scancodes); ++i) {
    2.19 -                if (scancode == alpha_scancodes[i]) {
    2.20 -                    wParam = 'A' + i;
    2.21 -                    break;
    2.22 -                }
    2.23 -            }
    2.24 -        }
    2.25 -    }
    2.26 -
    2.27 -    /* Keypad keys are a little trickier, we always scan for them.
    2.28 -       Keypad arrow keys have the same scancode as normal arrow keys,
    2.29 -       except they don't have the extended bit (0x1000000) set.
    2.30 -     */
    2.31 -    if (!(lParam & 0x1000000)) {
    2.32 -        if (wParam == VK_DELETE) {
    2.33 -            wParam = VK_DECIMAL;
    2.34 -        } else {
    2.35 -            for (i = 0; i < SDL_arraysize(keypad_scancodes); ++i) {
    2.36 -                if (scancode == keypad_scancodes[i]) {
    2.37 -                    wParam = VK_NUMPAD0 + i;
    2.38 -                    break;
    2.39 -                }
    2.40 -            }
    2.41 -        }
    2.42 -    }
    2.43 -
    2.44 -    return wParam;
    2.45 -}
    2.46 -
    2.47  static SDL_Scancode 
    2.48  WindowsScanCodeToSDLScanCode( int lParam, int wParam, const SDL_Scancode *key_map )
    2.49  {
    2.50 @@ -431,43 +391,7 @@
    2.51      case WM_SYSKEYDOWN:
    2.52      case WM_KEYDOWN:
    2.53          {
    2.54 -			SDL_Scancode code;
    2.55 -            wParam = RemapVKEY(wParam, lParam);
    2.56 -            switch (wParam) {
    2.57 -            case VK_CONTROL:
    2.58 -                if (lParam & EXTENDED_KEYMASK)
    2.59 -                    wParam = VK_RCONTROL;
    2.60 -                else
    2.61 -                    wParam = VK_LCONTROL;
    2.62 -                break;
    2.63 -            case VK_SHIFT:
    2.64 -                /* EXTENDED trick doesn't work here */
    2.65 -                {
    2.66 -                    Uint8 *state = SDL_GetKeyboardState(NULL);
    2.67 -                    if (state[SDL_SCANCODE_LSHIFT] == SDL_RELEASED
    2.68 -                        && (GetKeyState(VK_LSHIFT) & 0x8000)) {
    2.69 -                        wParam = VK_LSHIFT;
    2.70 -                    } else if (state[SDL_SCANCODE_RSHIFT] == SDL_RELEASED
    2.71 -                               && (GetKeyState(VK_RSHIFT) & 0x8000)) {
    2.72 -                        wParam = VK_RSHIFT;
    2.73 -                    } else {
    2.74 -                        /* Probably a key repeat */
    2.75 -                        wParam = 256;
    2.76 -                    }
    2.77 -                }
    2.78 -                break;
    2.79 -            case VK_MENU:
    2.80 -                if (lParam & EXTENDED_KEYMASK)
    2.81 -                    wParam = VK_RMENU;
    2.82 -                else
    2.83 -                    wParam = VK_LMENU;
    2.84 -                break;
    2.85 -            case VK_RETURN:
    2.86 -                if (lParam & EXTENDED_KEYMASK)
    2.87 -                    wParam = VK_ENTER;
    2.88 -                break;
    2.89 -            }
    2.90 -			code =  WindowsScanCodeToSDLScanCode( lParam, wParam, data->videodata->key_layout );
    2.91 +			SDL_Scancode code =  WindowsScanCodeToSDLScanCode( lParam, wParam, data->videodata->key_layout );
    2.92  			if ( code != SDL_SCANCODE_UNKNOWN ) {
    2.93                  SDL_SendKeyboardKey(SDL_PRESSED, code );
    2.94              }
    2.95 @@ -478,45 +402,7 @@
    2.96      case WM_SYSKEYUP:
    2.97      case WM_KEYUP:
    2.98          {
    2.99 -			SDL_Scancode code;
   2.100 -			wParam = RemapVKEY(wParam, lParam);
   2.101 -            switch (wParam) {
   2.102 -            case VK_CONTROL:
   2.103 -                if (lParam & EXTENDED_KEYMASK)
   2.104 -                    wParam = VK_RCONTROL;
   2.105 -                else
   2.106 -                    wParam = VK_LCONTROL;
   2.107 -                break;
   2.108 -            case VK_SHIFT:
   2.109 -                /* EXTENDED trick doesn't work here */
   2.110 -                {
   2.111 -                    Uint8 *state = SDL_GetKeyboardState(NULL);
   2.112 -                    if (state[SDL_SCANCODE_LSHIFT] == SDL_PRESSED
   2.113 -                        && !(GetKeyState(VK_LSHIFT) & 0x8000)) {
   2.114 -                        wParam = VK_LSHIFT;
   2.115 -                    } else if (state[SDL_SCANCODE_RSHIFT] == SDL_PRESSED
   2.116 -                               && !(GetKeyState(VK_RSHIFT) & 0x8000)) {
   2.117 -                        wParam = VK_RSHIFT;
   2.118 -                    } else {
   2.119 -                        /* Probably a key repeat */
   2.120 -                        wParam = 256;
   2.121 -                    }
   2.122 -                }
   2.123 -                break;
   2.124 -            case VK_MENU:
   2.125 -                if (lParam & EXTENDED_KEYMASK)
   2.126 -                    wParam = VK_RMENU;
   2.127 -                else
   2.128 -                    wParam = VK_LMENU;
   2.129 -                break;
   2.130 -            case VK_RETURN:
   2.131 -                if (lParam & EXTENDED_KEYMASK)
   2.132 -                    wParam = VK_ENTER;
   2.133 -                break;
   2.134 -            }
   2.135 -
   2.136 -            /* Windows only reports keyup for print screen */
   2.137 -			code =  WindowsScanCodeToSDLScanCode( lParam, wParam, data->videodata->key_layout );
   2.138 +			SDL_Scancode code =  WindowsScanCodeToSDLScanCode( lParam, wParam, data->videodata->key_layout );
   2.139  			if ( code != SDL_SCANCODE_UNKNOWN ) {
   2.140  				if (wParam == VK_SNAPSHOT
   2.141  				    && SDL_GetKeyboardState(NULL)[SDL_SCANCODE_PRINTSCREEN] ==
     3.1 --- a/src/video/windows/SDL_windowskeyboard.c	Mon Feb 25 16:52:50 2013 -0800
     3.2 +++ b/src/video/windows/SDL_windowskeyboard.c	Mon Feb 25 16:52:51 2013 -0800
     3.3 @@ -163,6 +163,12 @@
     3.4          if (scancode == SDL_SCANCODE_UNKNOWN ) {
     3.5              continue;
     3.6          }
     3.7 +		/* Don't allow the number keys right above the qwerty row to translate or the top left key (grave/backquote) */
     3.8 +		/* not mapping numbers fixes the AZERTY layout (french) causing non-shifted number to appear by default */
     3.9 +		if ( ( scancode >= SDL_SCANCODE_1 && scancode <= SDL_SCANCODE_0 ) || 
    3.10 +			  scancode == SDL_SCANCODE_GRAVE )  {
    3.11 +			continue;
    3.12 +		}
    3.13  
    3.14  		vk =  MapVirtualKey(i, MAPVK_VSC_TO_VK);
    3.15  		if ( vk ) {