# HG changeset patch # User Ryan C. Gordon # Date 1147922650 0 # Node ID eb2d5480ae95c97efff9f29e8a8cda71f0ad979f # Parent 536b0704b7d85d53295f2d3ad69d5d2aee22cd33 Try to keep SDL keysyms sane regardless of keyboard layout in windib target. Fixes Bugzilla #164. diff -r 536b0704b7d8 -r eb2d5480ae95 src/video/windib/SDL_dibevents.c --- a/src/video/windib/SDL_dibevents.c Wed May 17 23:42:48 2006 +0000 +++ b/src/video/windib/SDL_dibevents.c Thu May 18 03:24:10 2006 +0000 @@ -122,8 +122,16 @@ } 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 @@ } 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 @@ } } +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 @@ } #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 -r 536b0704b7d8 -r eb2d5480ae95 src/video/windx5/SDL_dx5events.c --- a/src/video/windx5/SDL_dx5events.c Wed May 17 23:42:48 2006 +0000 +++ b/src/video/windx5/SDL_dx5events.c Thu May 18 03:24:10 2006 +0000 @@ -750,7 +750,7 @@ 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;