From 9897a55a56d56de1ee69a24ac72d9f7587afa3c9 Mon Sep 17 00:00:00 2001 From: James Tabor Date: Fri, 22 May 2009 01:35:48 +0000 Subject: [PATCH] - Fix NtUserVkKeyScanEx to support current thread keyboard layout or use the one provided by handle. See bug report 4269 and the related bug report 4272. svn path=/trunk/; revision=41040 --- reactos/dll/win32/user32/windows/input.c | 4 +-- reactos/include/reactos/win32k/ntuser.h | 2 +- .../subsystems/win32/win32k/ntuser/keyboard.c | 32 +++++++++++++------ 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/reactos/dll/win32/user32/windows/input.c b/reactos/dll/win32/user32/windows/input.c index b7b22ef5f09..b440d0ffac8 100644 --- a/reactos/dll/win32/user32/windows/input.c +++ b/reactos/dll/win32/user32/windows/input.c @@ -492,7 +492,7 @@ SHORT WINAPI VkKeyScanExW(WCHAR ch, HKL dwhkl) { - return (SHORT) NtUserVkKeyScanEx(ch, dwhkl, 0); + return (SHORT) NtUserVkKeyScanEx(ch, dwhkl, TRUE); } @@ -502,7 +502,7 @@ VkKeyScanExW(WCHAR ch, SHORT WINAPI VkKeyScanW(WCHAR ch) { - return VkKeyScanExW(ch, GetKeyboardLayout(0)); + return (SHORT) NtUserVkKeyScanEx(ch, 0, FALSE); } diff --git a/reactos/include/reactos/win32k/ntuser.h b/reactos/include/reactos/win32k/ntuser.h index b942ae30a20..f8f30373723 100644 --- a/reactos/include/reactos/win32k/ntuser.h +++ b/reactos/include/reactos/win32k/ntuser.h @@ -2697,7 +2697,7 @@ NTAPI NtUserVkKeyScanEx( WCHAR wChar, HKL KeyboardLayout, - DWORD Unknown2); + BOOL bUsehHK); DWORD NTAPI diff --git a/reactos/subsystems/win32/win32k/ntuser/keyboard.c b/reactos/subsystems/win32/win32k/ntuser/keyboard.c index 32f9c7d0fd7..4f8de851934 100644 --- a/reactos/subsystems/win32/win32k/ntuser/keyboard.c +++ b/reactos/subsystems/win32/win32k/ntuser/keyboard.c @@ -1000,22 +1000,31 @@ DWORD APIENTRY NtUserVkKeyScanEx( WCHAR wChar, - HKL KeyboardLayout, - DWORD Unknown2) + HKL hKeyboardLayout, + BOOL UsehKL ) // TRUE from KeyboardLayout, FALSE from pkbl = (THREADINFO)->KeyboardLayout { -/* FIXME: currently, this routine doesnt seem to need any locking */ PKBDTABLES KeyLayout; PVK_TO_WCHAR_TABLE vtwTbl; PVK_TO_WCHARS10 vkPtr; size_t size_this_entry; int nMod; - DWORD CapsMod = 0, CapsState = 0; + PKBL pkbl = NULL; + DWORD CapsMod = 0, CapsState = 0, Ret = -1; - DPRINT("NtUserVkKeyScanEx() wChar %d, KbdLayout 0x%p\n", wChar, KeyboardLayout); + DPRINT("NtUserVkKeyScanEx() wChar %d, KbdLayout 0x%p\n", wChar, hKeyboardLayout); + UserEnterShared(); - if(!KeyboardLayout) - return -1; - KeyLayout = UserHklToKbl(KeyboardLayout)->KBTables; + if (UsehKL) + { + if ( !hKeyboardLayout || !(pkbl = UserHklToKbl(hKeyboardLayout))) + goto Exit; + } + else // From VkKeyScanAW it is FALSE so KeyboardLayout is white noise. + { + pkbl = ((PTHREADINFO)PsGetCurrentThreadWin32Thread())->KeyboardLayout; + } + + KeyLayout = pkbl->KBTables; for (nMod = 0; KeyLayout->pVkToWcharTable[nMod].nModifications; nMod++) { @@ -1038,13 +1047,16 @@ NtUserVkKeyScanEx( CapsMod = KeyLayout->pCharModifiers->ModNumber[CapsState]; DPRINT("nMod %d wC %04x: CapsMod %08x CapsState %08x MaxModBits %08x\n", nMod, wChar, CapsMod, CapsState, KeyLayout->pCharModifiers->wMaxModBits); - return ((CapsMod << 8)|(vkPtr->VirtualKey & 0xff)); + Ret = ((CapsMod << 8)|(vkPtr->VirtualKey & 0xff)); + goto Exit; } } vkPtr = (PVK_TO_WCHARS10)(((BYTE *)vkPtr) + size_this_entry); } } - return -1; +Exit: + UserLeave(); + return Ret; }