From b52a45bc3523d283f131ed4653d9073b147e8570 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Thu, 18 May 2006 03:24:10 +0000 Subject: [PATCH] Try to keep SDL keysyms sane regardless of keyboard layout in windib target. Fixes Bugzilla #164. --- src/video/windib/SDL_dibevents.c | 107 +++++++++++++++++++++++++++++-- src/video/windx5/SDL_dx5events.c | 2 +- 2 files changed, 102 insertions(+), 7 deletions(-) diff --git a/src/video/windib/SDL_dibevents.c b/src/video/windib/SDL_dibevents.c index c678b4d04..ce903c573 100644 --- a/src/video/windib/SDL_dibevents.c +++ b/src/video/windib/SDL_dibevents.c @@ -122,8 +122,16 @@ LRESULT DIB_HandleMessage(_THIS, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar } else if (state[SDLK_RSHIFT] == SDL_RELEASED && (GetKeyState(VK_RSHIFT) & 0x8000)) { wParam = VK_RSHIFT; } else { - /* Probably a key repeat */ - return(0); + /* Win9x */ + int sc = HIWORD(lParam) & 0xFF; + + if (sc == 0x2A) + wParam = VK_LSHIFT; + else + if (sc == 0x36) + wParam = VK_RSHIFT; + else + wParam = VK_LSHIFT; } } break; @@ -185,8 +193,16 @@ LRESULT DIB_HandleMessage(_THIS, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar } else if (state[SDLK_RSHIFT] == SDL_PRESSED && !(GetKeyState(VK_RSHIFT) & 0x8000)) { wParam = VK_RSHIFT; } else { - /* Probably a key repeat */ - return(0); + /* Win9x */ + int sc = HIWORD(lParam) & 0xFF; + + if (sc == 0x2A) + wParam = VK_LSHIFT; + else + if (sc == 0x36) + wParam = VK_RSHIFT; + else + wParam = VK_LSHIFT; } } break; @@ -252,9 +268,22 @@ void DIB_PumpEvents(_THIS) } } +static HKL hLayoutUS = NULL; + void DIB_InitOSKeymap(_THIS) { - int i; + int i; + char current_layout[256]; + + GetKeyboardLayoutName(current_layout); + //printf("Initial Keyboard Layout Name: '%s'\n", current_layout); + + hLayoutUS = LoadKeyboardLayout("00000409", KLF_NOTELLSHELL); + if (!hLayoutUS) { + //printf("Failed to load US keyboard layout. Using current.\n"); + hLayoutUS = GetKeyboardLayout(0); + } + LoadKeyboardLayout(current_layout, KLF_ACTIVATE); /* Map the VK keysyms */ for ( i=0; iscancode = (unsigned char) scancode; - keysym->sym = VK_keymap[vkey]; keysym->mod = KMOD_NONE; keysym->unicode = 0; if ( pressed && SDL_TranslateUNICODE ) { @@ -403,6 +474,30 @@ static SDL_keysym *TranslateKey(WPARAM vkey, UINT scancode, SDL_keysym *keysym, } #endif /* NO_GETKEYBOARDSTATE */ } + + if ((vkey == VK_RETURN) && (scancode & 0x100)) { + /* No VK_ code for the keypad enter key */ + keysym->sym = SDLK_KP_ENTER; + } + else { + keysym->sym = VK_keymap[SDL_MapVirtualKey(scancode, vkey)]; + } + +#if 0 + { + HKL hLayoutCurrent = GetKeyboardLayout(0); + int sc = scancode & 0xFF; + + printf("SYM:%d, VK:0x%02X, SC:0x%04X, US:(1:0x%02X, 3:0x%02X), " + "Current:(1:0x%02X, 3:0x%02X)\n", + keysym->sym, vkey, scancode, + MapVirtualKeyEx(sc, 1, hLayoutUS), + MapVirtualKeyEx(sc, 3, hLayoutUS), + MapVirtualKeyEx(sc, 1, hLayoutCurrent), + MapVirtualKeyEx(sc, 3, hLayoutCurrent) + ); + } +#endif return(keysym); } diff --git a/src/video/windx5/SDL_dx5events.c b/src/video/windx5/SDL_dx5events.c index 068a47baa..51373d376 100644 --- a/src/video/windx5/SDL_dx5events.c +++ b/src/video/windx5/SDL_dx5events.c @@ -750,7 +750,7 @@ void DX5_InitOSKeymap(_THIS) DIK_keymap[DIK_GRAVE] = SDLK_BACKQUOTE; DIK_keymap[DIK_LSHIFT] = SDLK_LSHIFT; DIK_keymap[DIK_BACKSLASH] = SDLK_BACKSLASH; - DIK_keymap[DIK_OEM_102] = SDLK_BACKSLASH; + DIK_keymap[DIK_OEM_102] = SDLK_LESS; DIK_keymap[DIK_Z] = SDLK_z; DIK_keymap[DIK_X] = SDLK_x; DIK_keymap[DIK_C] = SDLK_c;