From 09c6bf415ff2f0927cc186c5d8a89a6d62d6f224 Mon Sep 17 00:00:00 2001 From: Vitaliy Margolen Date: Sat, 26 Apr 2008 17:35:50 -0600 Subject: [PATCH] winex11: Fix MapVirtualKeyEx to properly map left-right modifier keys. --- dlls/user32/tests/input.c | 22 ++++++++++ dlls/winex11.drv/keyboard.c | 83 ++++++++++++++++++++++++++----------- 2 files changed, 80 insertions(+), 25 deletions(-) diff --git a/dlls/user32/tests/input.c b/dlls/user32/tests/input.c index a4e09a30ef..dd597d8320 100644 --- a/dlls/user32/tests/input.c +++ b/dlls/user32/tests/input.c @@ -1111,6 +1111,27 @@ static void test_GetMouseMovePointsEx(void) #undef MYERROR } +static void test_key_map(void) +{ + HKL kl = GetKeyboardLayout(0); + UINT kL, kR, s, sL; + + s = MapVirtualKeyEx(VK_SHIFT, MAPVK_VK_TO_VSC, kl); + ok(s != 0, "MapVirtualKeyEx(VK_SHIFT) should return non-zero\n"); + sL = MapVirtualKeyEx(VK_LSHIFT, MAPVK_VK_TO_VSC, kl); + ok(s == sL, "%x != %x\n", s, sL); + + kL = MapVirtualKeyEx(0x2a, MAPVK_VSC_TO_VK, kl); + ok(kL == VK_SHIFT, "Scan code -> vKey = %x (not VK_SHIFT)\n", kL); + kR = MapVirtualKeyEx(0x36, MAPVK_VSC_TO_VK, kl); + ok(kR == VK_SHIFT, "Scan code -> vKey = %x (not VK_SHIFT)\n", kR); + + kL = MapVirtualKeyEx(0x2a, MAPVK_VSC_TO_VK_EX, kl); + ok(kL == VK_LSHIFT, "Scan code -> vKey = %x (not VK_LSHIFT)\n", kL); + kR = MapVirtualKeyEx(0x36, MAPVK_VSC_TO_VK_EX, kl); + ok(kR == VK_RSHIFT, "Scan code -> vKey = %x (not VK_RSHIFT)\n", kR); +} + START_TEST(input) { init_function_pointers(); @@ -1123,6 +1144,7 @@ START_TEST(input) test_Input_blackbox(); test_keynames(); test_mouse_ll_hook(); + test_key_map(); if(pGetMouseMovePointsEx) test_GetMouseMovePointsEx(); diff --git a/dlls/winex11.drv/keyboard.c b/dlls/winex11.drv/keyboard.c index 917cc2e2d3..981e4df94e 100644 --- a/dlls/winex11.drv/keyboard.c +++ b/dlls/winex11.drv/keyboard.c @@ -2053,31 +2053,64 @@ UINT X11DRV_MapVirtualKeyEx(UINT wCode, UINT wMapType, HKL hkl) if (hkl != X11DRV_GetKeyboardLayout(0)) FIXME("keyboard layout %p is not supported\n", hkl); - switch(wMapType) { - case MAPVK_VK_TO_VSC: /* vkey-code to scan-code */ - case MAPVK_VK_TO_VSC_EX: /* FIXME: should differentiate between - left and right keys */ - { - /* let's do vkey -> keycode -> scan */ - int keyc; - for (keyc=min_keycode; keyc<=max_keycode; keyc++) - if ((keyc2vkey[keyc] & 0xFF) == wCode) - returnMVK (keyc2scan[keyc] & 0xFF); - TRACE("returning no scan-code.\n"); - return 0; - } - case MAPVK_VSC_TO_VK: /* scan-code to vkey-code */ - case MAPVK_VSC_TO_VK_EX: /* FIXME: should differentiate between - left and right keys */ - { - /* let's do scan -> keycode -> vkey */ - int keyc; - for (keyc=min_keycode; keyc<=max_keycode; keyc++) - if ((keyc2scan[keyc] & 0xFF) == (wCode & 0xFF)) - returnMVK (keyc2vkey[keyc] & 0xFF); - TRACE("returning no vkey-code.\n"); - return 0; - } + switch(wMapType) + { + case MAPVK_VK_TO_VSC: /* vkey-code to scan-code */ + case MAPVK_VK_TO_VSC_EX: + { + int keyc; + + switch (wCode) + { + case VK_SHIFT: wCode = VK_LSHIFT; break; + case VK_CONTROL: wCode = VK_LCONTROL; break; + case VK_MENU: wCode = VK_LMENU; break; + } + + /* let's do vkey -> keycode -> scan */ + for (keyc = min_keycode; keyc <= max_keycode; keyc++) + if ((keyc2vkey[keyc] & 0xFF) == wCode) break; + + if (keyc > max_keycode) + { + TRACE("returning no scan-code.\n"); + return 0; + } + returnMVK (keyc2scan[keyc] & 0xFF); + } + case MAPVK_VSC_TO_VK: /* scan-code to vkey-code */ + case MAPVK_VSC_TO_VK_EX: + { + int keyc; + UINT vkey; + + /* let's do scan -> keycode -> vkey */ + for (keyc = min_keycode; keyc <= max_keycode; keyc++) + if ((keyc2scan[keyc] & 0xFF) == (wCode & 0xFF)) break; + + if (keyc > max_keycode) + { + TRACE("returning no vkey-code.\n"); + return 0; + } + + vkey = keyc2vkey[keyc] & 0xFF; + if (wMapType == MAPVK_VSC_TO_VK) + switch (vkey) + { + case VK_LSHIFT: + case VK_RSHIFT: + vkey = VK_SHIFT; break; + case VK_LCONTROL: + case VK_RCONTROL: + vkey = VK_CONTROL; break; + case VK_LMENU: + case VK_RMENU: + vkey = VK_MENU; break; + } + + returnMVK (vkey); + } case MAPVK_VK_TO_CHAR: /* vkey-code to unshifted ANSI code */ { /* we still don't know what "unshifted" means. in windows VK_W (0x57) -- 2.32.0.93.g670b81a890