sdl2
authorJørgen P. Tjernø <jorgen@valvesoftware.com>
Mon, 25 Feb 2013 16:52:51 -0800
changeset 6925 59fedfb8faaf
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
--- a/src/events/scancodes_windows.h	Mon Feb 25 16:52:50 2013 -0800
+++ b/src/events/scancodes_windows.h	Mon Feb 25 16:52:51 2013 -0800
@@ -29,31 +29,31 @@
 // Google for 'Keyboard Scan Code Specification'
 static const SDL_Scancode windows_scancode_table[] = 
 { 
-	//	0						1							2						3						4							5							6						7 
-	//	8						9							A						B						C							D							E						F 
-	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
-	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 
+	//	0						1							2							3							4						5							6							7 
+	//	8						9							A							B							C						D							E							F 
+	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
+	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 
 
-	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
-	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 
+	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
+	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 
 
-	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 
-	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 
+	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 
+	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 
 
-	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
-	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 
+	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
+	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 
 
-	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
-	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 
+	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
+	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 
 
-	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
-	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
+	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
+	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
 
-	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
-	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 
+	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
+	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 
 	
-	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
-	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 
+	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
+	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 
 };
 
 /* *INDENT-ON* */
--- a/src/video/windows/SDL_windowsevents.c	Mon Feb 25 16:52:50 2013 -0800
+++ b/src/video/windows/SDL_windowsevents.c	Mon Feb 25 16:52:51 2013 -0800
@@ -65,46 +65,6 @@
 #endif
 
 
-static WPARAM
-RemapVKEY(WPARAM wParam, LPARAM lParam)
-{
-    int i;
-    BYTE scancode = (BYTE) ((lParam >> 16) & 0xFF);
-
-    /* Windows remaps alphabetic keys based on current layout.
-       We try to provide USB scancodes, so undo this mapping.
-     */
-    if (wParam >= 'A' && wParam <= 'Z') {
-        if (scancode != alpha_scancodes[wParam - 'A']) {
-            for (i = 0; i < SDL_arraysize(alpha_scancodes); ++i) {
-                if (scancode == alpha_scancodes[i]) {
-                    wParam = 'A' + i;
-                    break;
-                }
-            }
-        }
-    }
-
-    /* Keypad keys are a little trickier, we always scan for them.
-       Keypad arrow keys have the same scancode as normal arrow keys,
-       except they don't have the extended bit (0x1000000) set.
-     */
-    if (!(lParam & 0x1000000)) {
-        if (wParam == VK_DELETE) {
-            wParam = VK_DECIMAL;
-        } else {
-            for (i = 0; i < SDL_arraysize(keypad_scancodes); ++i) {
-                if (scancode == keypad_scancodes[i]) {
-                    wParam = VK_NUMPAD0 + i;
-                    break;
-                }
-            }
-        }
-    }
-
-    return wParam;
-}
-
 static SDL_Scancode 
 WindowsScanCodeToSDLScanCode( int lParam, int wParam, const SDL_Scancode *key_map )
 {
@@ -431,43 +391,7 @@
     case WM_SYSKEYDOWN:
     case WM_KEYDOWN:
         {
-			SDL_Scancode code;
-            wParam = RemapVKEY(wParam, lParam);
-            switch (wParam) {
-            case VK_CONTROL:
-                if (lParam & EXTENDED_KEYMASK)
-                    wParam = VK_RCONTROL;
-                else
-                    wParam = VK_LCONTROL;
-                break;
-            case VK_SHIFT:
-                /* EXTENDED trick doesn't work here */
-                {
-                    Uint8 *state = SDL_GetKeyboardState(NULL);
-                    if (state[SDL_SCANCODE_LSHIFT] == SDL_RELEASED
-                        && (GetKeyState(VK_LSHIFT) & 0x8000)) {
-                        wParam = VK_LSHIFT;
-                    } else if (state[SDL_SCANCODE_RSHIFT] == SDL_RELEASED
-                               && (GetKeyState(VK_RSHIFT) & 0x8000)) {
-                        wParam = VK_RSHIFT;
-                    } else {
-                        /* Probably a key repeat */
-                        wParam = 256;
-                    }
-                }
-                break;
-            case VK_MENU:
-                if (lParam & EXTENDED_KEYMASK)
-                    wParam = VK_RMENU;
-                else
-                    wParam = VK_LMENU;
-                break;
-            case VK_RETURN:
-                if (lParam & EXTENDED_KEYMASK)
-                    wParam = VK_ENTER;
-                break;
-            }
-			code =  WindowsScanCodeToSDLScanCode( lParam, wParam, data->videodata->key_layout );
+			SDL_Scancode code =  WindowsScanCodeToSDLScanCode( lParam, wParam, data->videodata->key_layout );
 			if ( code != SDL_SCANCODE_UNKNOWN ) {
                 SDL_SendKeyboardKey(SDL_PRESSED, code );
             }
@@ -478,45 +402,7 @@
     case WM_SYSKEYUP:
     case WM_KEYUP:
         {
-			SDL_Scancode code;
-			wParam = RemapVKEY(wParam, lParam);
-            switch (wParam) {
-            case VK_CONTROL:
-                if (lParam & EXTENDED_KEYMASK)
-                    wParam = VK_RCONTROL;
-                else
-                    wParam = VK_LCONTROL;
-                break;
-            case VK_SHIFT:
-                /* EXTENDED trick doesn't work here */
-                {
-                    Uint8 *state = SDL_GetKeyboardState(NULL);
-                    if (state[SDL_SCANCODE_LSHIFT] == SDL_PRESSED
-                        && !(GetKeyState(VK_LSHIFT) & 0x8000)) {
-                        wParam = VK_LSHIFT;
-                    } else if (state[SDL_SCANCODE_RSHIFT] == SDL_PRESSED
-                               && !(GetKeyState(VK_RSHIFT) & 0x8000)) {
-                        wParam = VK_RSHIFT;
-                    } else {
-                        /* Probably a key repeat */
-                        wParam = 256;
-                    }
-                }
-                break;
-            case VK_MENU:
-                if (lParam & EXTENDED_KEYMASK)
-                    wParam = VK_RMENU;
-                else
-                    wParam = VK_LMENU;
-                break;
-            case VK_RETURN:
-                if (lParam & EXTENDED_KEYMASK)
-                    wParam = VK_ENTER;
-                break;
-            }
-
-            /* Windows only reports keyup for print screen */
-			code =  WindowsScanCodeToSDLScanCode( lParam, wParam, data->videodata->key_layout );
+			SDL_Scancode code =  WindowsScanCodeToSDLScanCode( lParam, wParam, data->videodata->key_layout );
 			if ( code != SDL_SCANCODE_UNKNOWN ) {
 				if (wParam == VK_SNAPSHOT
 				    && SDL_GetKeyboardState(NULL)[SDL_SCANCODE_PRINTSCREEN] ==
--- a/src/video/windows/SDL_windowskeyboard.c	Mon Feb 25 16:52:50 2013 -0800
+++ b/src/video/windows/SDL_windowskeyboard.c	Mon Feb 25 16:52:51 2013 -0800
@@ -163,6 +163,12 @@
         if (scancode == SDL_SCANCODE_UNKNOWN ) {
             continue;
         }
+		/* Don't allow the number keys right above the qwerty row to translate or the top left key (grave/backquote) */
+		/* not mapping numbers fixes the AZERTY layout (french) causing non-shifted number to appear by default */
+		if ( ( scancode >= SDL_SCANCODE_1 && scancode <= SDL_SCANCODE_0 ) || 
+			  scancode == SDL_SCANCODE_GRAVE )  {
+			continue;
+		}
 
 		vk =  MapVirtualKey(i, MAPVK_VSC_TO_VK);
 		if ( vk ) {