2003-05-18 17:16:18 +00:00
|
|
|
/*
|
|
|
|
* ReactOS W32 Subsystem
|
|
|
|
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
2009-10-27 10:34:16 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2003-05-18 17:16:18 +00:00
|
|
|
*/
|
2005-01-06 15:57:38 +00:00
|
|
|
/*
|
2002-01-27 14:47:44 +00:00
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS kernel
|
|
|
|
* PURPOSE: Messages
|
2003-07-05 16:04:01 +00:00
|
|
|
* FILE: subsys/win32k/ntuser/keyboard.c
|
2002-01-27 14:47:44 +00:00
|
|
|
* PROGRAMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
|
|
|
|
* REVISION HISTORY:
|
|
|
|
* 06-06-2001 CSH Created
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES ******************************************************************/
|
|
|
|
|
2010-04-26 13:58:46 +00:00
|
|
|
#include <win32k.h>
|
2002-01-27 14:47:44 +00:00
|
|
|
|
2011-08-21 12:38:52 +00:00
|
|
|
DBG_DEFAULT_CHANNEL(UserKbd);
|
2002-01-27 14:47:44 +00:00
|
|
|
|
2011-09-09 13:11:44 +00:00
|
|
|
BYTE gKeyStateTable[0x100];
|
2003-07-29 23:03:01 +00:00
|
|
|
|
|
|
|
/* FUNCTIONS *****************************************************************/
|
|
|
|
|
2003-11-24 00:22:53 +00:00
|
|
|
/* Initialization -- Right now, just zero the key state and init the lock */
|
2010-11-03 00:51:19 +00:00
|
|
|
INIT_FUNCTION
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
InitKeyboardImpl(VOID)
|
2005-09-07 21:25:42 +00:00
|
|
|
{
|
2011-09-09 16:17:02 +00:00
|
|
|
RtlZeroMemory(&gKeyStateTable, 0x100);
|
|
|
|
return STATUS_SUCCESS;
|
2003-11-24 00:22:53 +00:00
|
|
|
}
|
|
|
|
|
2003-07-29 23:03:01 +00:00
|
|
|
/*** Statics used by TranslateMessage ***/
|
|
|
|
|
2004-02-19 06:59:50 +00:00
|
|
|
/*** Shift state code was out of hand, sorry. --- arty */
|
2004-02-19 03:45:44 +00:00
|
|
|
|
2005-09-07 21:25:42 +00:00
|
|
|
static UINT DontDistinguishShifts( UINT ret )
|
|
|
|
{
|
2011-09-09 16:17:02 +00:00
|
|
|
if( ret == VK_LSHIFT || ret == VK_RSHIFT )
|
|
|
|
ret = VK_SHIFT;
|
|
|
|
if( ret == VK_LCONTROL || ret == VK_RCONTROL )
|
|
|
|
ret = VK_CONTROL;
|
|
|
|
if( ret == VK_LMENU || ret == VK_RMENU )
|
|
|
|
ret = VK_MENU;
|
|
|
|
return ret;
|
2003-10-09 06:13:05 +00:00
|
|
|
}
|
|
|
|
|
2008-11-29 22:48:58 +00:00
|
|
|
static VOID APIENTRY SetKeyState(DWORD key, DWORD vk, DWORD ext, BOOL down)
|
2005-09-07 21:25:42 +00:00
|
|
|
{
|
2011-09-09 16:17:02 +00:00
|
|
|
ASSERT(vk <= 0xff);
|
|
|
|
|
|
|
|
/* Special handling for toggles like numpad and caps lock */
|
|
|
|
if (vk == VK_CAPITAL || vk == VK_NUMLOCK)
|
|
|
|
{
|
|
|
|
if (down)
|
|
|
|
gKeyStateTable[vk] ^= KS_LOCK_BIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vk == VK_SHIFT)
|
|
|
|
vk = ext ? VK_RSHIFT : VK_LSHIFT;
|
|
|
|
if (vk == VK_CONTROL)
|
|
|
|
vk = ext ? VK_RCONTROL : VK_LCONTROL;
|
|
|
|
if (vk == VK_MENU)
|
|
|
|
vk = ext ? VK_RMENU : VK_LMENU;
|
|
|
|
|
|
|
|
if (down)
|
|
|
|
gKeyStateTable[vk] |= KS_DOWN_BIT;
|
|
|
|
else
|
|
|
|
gKeyStateTable[vk] &= ~KS_DOWN_BIT;
|
|
|
|
|
|
|
|
if (vk == VK_LSHIFT || vk == VK_RSHIFT)
|
|
|
|
{
|
|
|
|
if ((gKeyStateTable[VK_LSHIFT] & KS_DOWN_BIT) ||
|
|
|
|
(gKeyStateTable[VK_RSHIFT] & KS_DOWN_BIT))
|
|
|
|
{
|
|
|
|
gKeyStateTable[VK_SHIFT] |= KS_DOWN_BIT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gKeyStateTable[VK_SHIFT] &= ~KS_DOWN_BIT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vk == VK_LCONTROL || vk == VK_RCONTROL)
|
|
|
|
{
|
|
|
|
if ((gKeyStateTable[VK_LCONTROL] & KS_DOWN_BIT) ||
|
|
|
|
(gKeyStateTable[VK_RCONTROL] & KS_DOWN_BIT))
|
|
|
|
{
|
|
|
|
gKeyStateTable[VK_CONTROL] |= KS_DOWN_BIT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gKeyStateTable[VK_CONTROL] &= ~KS_DOWN_BIT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vk == VK_LMENU || vk == VK_RMENU)
|
|
|
|
{
|
|
|
|
if ((gKeyStateTable[VK_LMENU] & KS_DOWN_BIT) ||
|
|
|
|
(gKeyStateTable[VK_RMENU] & KS_DOWN_BIT))
|
|
|
|
{
|
|
|
|
gKeyStateTable[VK_MENU] |= KS_DOWN_BIT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gKeyStateTable[VK_MENU] &= ~KS_DOWN_BIT;
|
|
|
|
}
|
|
|
|
}
|
2005-09-07 21:25:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VOID DumpKeyState( PBYTE KeyState )
|
|
|
|
{
|
2011-09-09 16:17:02 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
DbgPrint( "KeyState { " );
|
|
|
|
for( i = 0; i < 0x100; i++ )
|
|
|
|
{
|
|
|
|
if( KeyState[i] )
|
|
|
|
DbgPrint( "%02x(%02x) ", i, KeyState[i] );
|
|
|
|
}
|
|
|
|
DbgPrint( "};\n" );
|
2003-10-09 06:13:05 +00:00
|
|
|
}
|
|
|
|
|
2005-05-08 02:11:54 +00:00
|
|
|
static BYTE KeysSet( PKBDTABLES pkKT, PBYTE KeyState,
|
2005-09-07 21:25:42 +00:00
|
|
|
int FakeModLeft, int FakeModRight )
|
|
|
|
{
|
2011-09-09 16:17:02 +00:00
|
|
|
if( !KeyState || !pkKT )
|
|
|
|
return 0;
|
2003-10-09 06:13:05 +00:00
|
|
|
|
2011-09-09 16:17:02 +00:00
|
|
|
/* Search special codes first */
|
|
|
|
if( FakeModLeft && KeyState[FakeModLeft] )
|
|
|
|
return KeyState[FakeModLeft];
|
|
|
|
else if( FakeModRight && KeyState[FakeModRight] )
|
|
|
|
return KeyState[FakeModRight];
|
2003-07-29 23:03:01 +00:00
|
|
|
|
2011-09-09 16:17:02 +00:00
|
|
|
return 0;
|
2003-07-29 23:03:01 +00:00
|
|
|
}
|
|
|
|
|
2004-02-19 06:59:50 +00:00
|
|
|
/* Search the keyboard layout modifiers table for the shift bit. I don't
|
|
|
|
* want to count on the shift bit not moving, because it can be specified
|
|
|
|
* in the layout */
|
|
|
|
|
2005-09-07 21:25:42 +00:00
|
|
|
static DWORD FASTCALL GetShiftBit( PKBDTABLES pkKT, DWORD Vk )
|
|
|
|
{
|
2011-09-09 16:17:02 +00:00
|
|
|
int i;
|
2004-02-19 06:59:50 +00:00
|
|
|
|
2011-09-09 16:17:02 +00:00
|
|
|
for( i = 0; pkKT->pCharModifiers->pVkToBit[i].Vk; i++ )
|
|
|
|
if( pkKT->pCharModifiers->pVkToBit[i].Vk == Vk )
|
|
|
|
return pkKT->pCharModifiers->pVkToBit[i].ModBits;
|
2004-02-19 06:59:50 +00:00
|
|
|
|
2011-09-09 16:17:02 +00:00
|
|
|
return 0;
|
2004-02-19 06:59:50 +00:00
|
|
|
}
|
|
|
|
|
2005-09-07 21:25:42 +00:00
|
|
|
static DWORD ModBits( PKBDTABLES pkKT, PBYTE KeyState )
|
|
|
|
{
|
2011-09-09 16:17:02 +00:00
|
|
|
DWORD ModBits = 0;
|
2003-10-09 06:13:05 +00:00
|
|
|
|
2011-09-09 16:17:02 +00:00
|
|
|
if( !KeyState )
|
|
|
|
return 0;
|
2003-10-09 06:13:05 +00:00
|
|
|
|
2011-09-09 16:17:02 +00:00
|
|
|
/* DumpKeyState( KeyState ); */
|
2003-10-09 06:13:05 +00:00
|
|
|
|
2011-09-09 16:17:02 +00:00
|
|
|
if (KeysSet( pkKT, KeyState, VK_LSHIFT, VK_RSHIFT ) &
|
|
|
|
KS_DOWN_BIT)
|
|
|
|
ModBits |= GetShiftBit( pkKT, VK_SHIFT );
|
2005-05-08 02:11:54 +00:00
|
|
|
|
2011-09-09 16:17:02 +00:00
|
|
|
if (KeysSet( pkKT, KeyState, VK_SHIFT, 0 ) &
|
|
|
|
KS_DOWN_BIT)
|
|
|
|
ModBits |= GetShiftBit( pkKT, VK_SHIFT );
|
2007-11-10 04:53:02 +00:00
|
|
|
|
2011-09-09 16:17:02 +00:00
|
|
|
if (KeysSet( pkKT, KeyState, VK_LCONTROL, VK_RCONTROL ) &
|
|
|
|
KS_DOWN_BIT )
|
|
|
|
ModBits |= GetShiftBit( pkKT, VK_CONTROL );
|
2004-02-19 06:59:50 +00:00
|
|
|
|
2011-09-09 16:17:02 +00:00
|
|
|
if (KeysSet( pkKT, KeyState, VK_CONTROL, 0 ) &
|
|
|
|
KS_DOWN_BIT )
|
|
|
|
ModBits |= GetShiftBit( pkKT, VK_CONTROL );
|
2007-11-10 04:53:02 +00:00
|
|
|
|
2011-09-09 16:17:02 +00:00
|
|
|
if (KeysSet( pkKT, KeyState, VK_LMENU, VK_RMENU ) &
|
|
|
|
KS_DOWN_BIT )
|
|
|
|
ModBits |= GetShiftBit( pkKT, VK_MENU );
|
2004-02-19 06:59:50 +00:00
|
|
|
|
2011-09-09 16:17:02 +00:00
|
|
|
/* Handle Alt+Gr */
|
|
|
|
if (pkKT->fLocalFlags & 0x1)
|
|
|
|
if (KeysSet( pkKT, KeyState, VK_RMENU, 0 ) &
|
|
|
|
KS_DOWN_BIT)
|
|
|
|
ModBits |= GetShiftBit( pkKT, VK_CONTROL );
|
2005-05-08 02:11:54 +00:00
|
|
|
|
2011-09-09 16:17:02 +00:00
|
|
|
/* Deal with VK_CAPITAL */
|
|
|
|
if (KeysSet( pkKT, KeyState, VK_CAPITAL, 0 ) & KS_LOCK_BIT)
|
|
|
|
{
|
|
|
|
ModBits |= CAPITAL_BIT;
|
|
|
|
}
|
2003-11-24 00:22:53 +00:00
|
|
|
|
2011-09-09 16:17:02 +00:00
|
|
|
/* Deal with VK_NUMLOCK */
|
|
|
|
if (KeysSet( pkKT, KeyState, VK_NUMLOCK, 0 ) & KS_LOCK_BIT)
|
|
|
|
{
|
|
|
|
ModBits |= NUMLOCK_BIT;
|
|
|
|
}
|
2003-11-24 00:22:53 +00:00
|
|
|
|
2011-09-09 16:17:02 +00:00
|
|
|
TRACE( "Current Mod Bits: %x\n", ModBits );
|
2003-10-09 06:13:05 +00:00
|
|
|
|
2011-09-09 16:17:02 +00:00
|
|
|
return ModBits;
|
2003-10-09 06:13:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL TryToTranslateChar(WORD wVirtKey,
|
2005-09-07 21:25:42 +00:00
|
|
|
DWORD ModBits,
|
|
|
|
PBOOL pbDead,
|
|
|
|
PBOOL pbLigature,
|
|
|
|
PWCHAR pwcTranslatedChar,
|
|
|
|
PKBDTABLES keyLayout )
|
2003-10-09 06:13:05 +00:00
|
|
|
{
|
2011-09-09 16:17:02 +00:00
|
|
|
PVK_TO_WCHAR_TABLE vtwTbl;
|
|
|
|
PVK_TO_WCHARS10 vkPtr;
|
|
|
|
size_t size_this_entry;
|
|
|
|
int nMod;
|
|
|
|
DWORD CapsMod = 0, CapsState = 0;
|
2005-09-07 21:25:42 +00:00
|
|
|
|
2011-09-09 16:17:02 +00:00
|
|
|
CapsState = ModBits & ~MOD_BITS_MASK;
|
|
|
|
ModBits = ModBits & MOD_BITS_MASK;
|
2005-09-07 21:25:42 +00:00
|
|
|
|
2011-09-09 16:17:02 +00:00
|
|
|
TRACE ( "TryToTranslate: %04x %x\n", wVirtKey, ModBits );
|
2005-09-07 21:25:42 +00:00
|
|
|
|
2011-09-09 16:17:02 +00:00
|
|
|
if (ModBits > keyLayout->pCharModifiers->wMaxModBits)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2005-09-07 21:25:42 +00:00
|
|
|
|
2011-09-09 16:17:02 +00:00
|
|
|
for (nMod = 0; keyLayout->pVkToWcharTable[nMod].nModifications; nMod++)
|
|
|
|
{
|
|
|
|
vtwTbl = &keyLayout->pVkToWcharTable[nMod];
|
|
|
|
size_this_entry = vtwTbl->cbSize;
|
|
|
|
vkPtr = (PVK_TO_WCHARS10)((BYTE *)vtwTbl->pVkToWchars);
|
|
|
|
while(vkPtr->VirtualKey)
|
|
|
|
{
|
|
|
|
if( wVirtKey == (vkPtr->VirtualKey & 0xff) )
|
2005-09-07 21:25:42 +00:00
|
|
|
{
|
2011-09-09 16:17:02 +00:00
|
|
|
CapsMod = keyLayout->pCharModifiers->ModNumber
|
|
|
|
[ModBits ^
|
|
|
|
((CapsState & CAPITAL_BIT) ? vkPtr->Attributes : 0)];
|
|
|
|
|
|
|
|
if( CapsMod >= keyLayout->pVkToWcharTable[nMod].nModifications )
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( vkPtr->wch[CapsMod] == WCH_NONE )
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*pbDead = vkPtr->wch[CapsMod] == WCH_DEAD;
|
|
|
|
*pbLigature = vkPtr->wch[CapsMod] == WCH_LGTR;
|
|
|
|
*pwcTranslatedChar = vkPtr->wch[CapsMod];
|
|
|
|
|
|
|
|
TRACE("%d %04x: CapsMod %08x CapsState %08x Char %04x\n",
|
|
|
|
nMod, wVirtKey,
|
|
|
|
CapsMod, CapsState, *pwcTranslatedChar);
|
|
|
|
|
|
|
|
if( *pbDead )
|
|
|
|
{
|
|
|
|
vkPtr = (PVK_TO_WCHARS10)(((BYTE *)vkPtr) + size_this_entry);
|
|
|
|
if( vkPtr->VirtualKey != 0xff )
|
|
|
|
{
|
|
|
|
TRACE( "Found dead key with no trailer in the table.\n" );
|
|
|
|
TRACE( "VK: %04x, ADDR: %p\n", wVirtKey, vkPtr );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
*pwcTranslatedChar = vkPtr->wch[CapsMod];
|
|
|
|
}
|
|
|
|
return TRUE;
|
2005-09-07 21:25:42 +00:00
|
|
|
}
|
2011-09-09 16:17:02 +00:00
|
|
|
vkPtr = (PVK_TO_WCHARS10)(((BYTE *)vkPtr) + size_this_entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
2003-07-29 23:03:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
2008-11-29 22:48:58 +00:00
|
|
|
int APIENTRY
|
2003-07-29 23:03:01 +00:00
|
|
|
ToUnicodeInner(UINT wVirtKey,
|
2005-09-07 21:25:42 +00:00
|
|
|
UINT wScanCode,
|
|
|
|
PBYTE lpKeyState,
|
|
|
|
LPWSTR pwszBuff,
|
|
|
|
int cchBuff,
|
|
|
|
UINT wFlags,
|
|
|
|
PKBDTABLES pkKT)
|
2002-01-27 14:47:44 +00:00
|
|
|
{
|
2011-09-09 16:17:02 +00:00
|
|
|
WCHAR wcTranslatedChar;
|
|
|
|
BOOL bDead;
|
|
|
|
BOOL bLigature;
|
|
|
|
|
|
|
|
if( !pkKT )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if( TryToTranslateChar( wVirtKey,
|
|
|
|
ModBits( pkKT, lpKeyState ),
|
|
|
|
&bDead,
|
|
|
|
&bLigature,
|
|
|
|
&wcTranslatedChar,
|
|
|
|
pkKT ) )
|
|
|
|
{
|
|
|
|
if( bLigature )
|
|
|
|
{
|
|
|
|
WARN("Not handling ligature (yet)\n" );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( cchBuff > 0 )
|
|
|
|
pwszBuff[0] = wcTranslatedChar;
|
|
|
|
|
|
|
|
return bDead ? -1 : 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2003-07-29 23:03:01 +00:00
|
|
|
}
|
|
|
|
|
2005-09-05 21:19:23 +00:00
|
|
|
|
|
|
|
DWORD FASTCALL UserGetAsyncKeyState(DWORD key)
|
2005-07-08 12:16:47 +00:00
|
|
|
{
|
2011-09-09 16:17:02 +00:00
|
|
|
DWORD ret = 0;
|
|
|
|
|
|
|
|
if( key < 0x100 )
|
|
|
|
{
|
|
|
|
ret = ((DWORD)(gKeyStateTable[key] & KS_DOWN_BIT) << 8 ) |
|
|
|
|
(gKeyStateTable[key] & KS_LOCK_BIT);
|
|
|
|
if ( ret & 0x8000 )
|
|
|
|
ret |= 0xFFFF0000; // If down, windows returns 0xFFFF8000.
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
EngSetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
}
|
|
|
|
return ret;
|
2005-07-08 12:16:47 +00:00
|
|
|
}
|
|
|
|
|
2011-04-08 19:29:15 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* get_key_state
|
|
|
|
*/
|
|
|
|
WORD FASTCALL get_key_state(void)
|
|
|
|
{
|
|
|
|
WORD ret = 0;
|
|
|
|
|
|
|
|
if (gpsi->aiSysMet[SM_SWAPBUTTON])
|
|
|
|
{
|
2011-09-09 13:11:44 +00:00
|
|
|
if (gKeyStateTable[VK_RBUTTON] & KS_DOWN_BIT) ret |= MK_LBUTTON;
|
|
|
|
if (gKeyStateTable[VK_LBUTTON] & KS_DOWN_BIT) ret |= MK_RBUTTON;
|
2011-04-08 19:29:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-09-09 13:11:44 +00:00
|
|
|
if (gKeyStateTable[VK_LBUTTON] & KS_DOWN_BIT) ret |= MK_LBUTTON;
|
|
|
|
if (gKeyStateTable[VK_RBUTTON] & KS_DOWN_BIT) ret |= MK_RBUTTON;
|
2011-04-08 19:29:15 +00:00
|
|
|
}
|
2011-09-09 13:11:44 +00:00
|
|
|
if (gKeyStateTable[VK_MBUTTON] & KS_DOWN_BIT) ret |= MK_MBUTTON;
|
|
|
|
if (gKeyStateTable[VK_SHIFT] & KS_DOWN_BIT) ret |= MK_SHIFT;
|
|
|
|
if (gKeyStateTable[VK_CONTROL] & KS_DOWN_BIT) ret |= MK_CONTROL;
|
|
|
|
if (gKeyStateTable[VK_XBUTTON1] & KS_DOWN_BIT) ret |= MK_XBUTTON1;
|
|
|
|
if (gKeyStateTable[VK_XBUTTON2] & KS_DOWN_BIT) ret |= MK_XBUTTON2;
|
2011-04-08 19:29:15 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2005-07-08 12:16:47 +00:00
|
|
|
|
2008-07-08 07:38:28 +00:00
|
|
|
SHORT
|
2008-11-29 22:48:58 +00:00
|
|
|
APIENTRY
|
2005-09-05 21:19:23 +00:00
|
|
|
NtUserGetAsyncKeyState(
|
2011-09-09 16:17:02 +00:00
|
|
|
INT key)
|
2005-09-05 21:19:23 +00:00
|
|
|
{
|
2011-09-09 16:17:02 +00:00
|
|
|
DECLARE_RETURN(SHORT);
|
2005-09-07 21:25:42 +00:00
|
|
|
|
2011-09-09 16:17:02 +00:00
|
|
|
TRACE("Enter NtUserGetAsyncKeyState\n");
|
|
|
|
UserEnterExclusive();
|
2005-09-07 21:25:42 +00:00
|
|
|
|
2011-09-09 16:17:02 +00:00
|
|
|
RETURN((SHORT)UserGetAsyncKeyState(key));
|
2005-09-05 21:19:23 +00:00
|
|
|
|
|
|
|
CLEANUP:
|
2011-09-09 16:17:02 +00:00
|
|
|
TRACE("Leave NtUserGetAsyncKeyState, ret=%i\n", _ret_);
|
|
|
|
UserLeave();
|
|
|
|
END_CLEANUP;
|
2005-09-05 21:19:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-12-28 14:21:03 +00:00
|
|
|
BOOL FASTCALL
|
|
|
|
IntTranslateKbdMessage(LPMSG lpMsg,
|
2010-03-25 12:48:03 +00:00
|
|
|
UINT flags)
|
2002-01-27 14:47:44 +00:00
|
|
|
{
|
2011-09-09 16:17:02 +00:00
|
|
|
PTHREADINFO pti;
|
|
|
|
static INT dead_char = 0;
|
|
|
|
LONG UState = 0;
|
|
|
|
WCHAR wp[2] = { 0 };
|
|
|
|
MSG NewMsg = { 0 };
|
|
|
|
PKBDTABLES keyLayout;
|
|
|
|
PWND pWndMsg;
|
|
|
|
BOOL Result = FALSE;
|
|
|
|
|
|
|
|
pWndMsg = UserGetWindowObject(lpMsg->hwnd);
|
|
|
|
if (!pWndMsg) // Must have a window!
|
|
|
|
{
|
|
|
|
ERR("No Window for Translate.\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
pti = pWndMsg->head.pti;
|
|
|
|
keyLayout = pti->KeyboardLayout->KBTables;
|
|
|
|
if( !keyLayout )
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (lpMsg->message < WM_KEYFIRST || lpMsg->message > WM_KEYLAST)
|
|
|
|
return FALSE;
|
|
|
|
if (lpMsg->message != WM_KEYDOWN && lpMsg->message != WM_SYSKEYDOWN)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* All messages have to contain the cursor point. */
|
|
|
|
NewMsg.pt = gpsi->ptCursor;
|
|
|
|
|
|
|
|
TRACE("IntTranslateKbdMessage %s\n", lpMsg->message == WM_SYSKEYDOWN ? "WM_SYSKEYDOWN" : "WM_KEYDOWN");
|
2011-05-04 23:37:35 +00:00
|
|
|
|
2009-10-26 08:50:00 +00:00
|
|
|
switch (lpMsg->wParam)
|
|
|
|
{
|
2011-09-09 16:17:02 +00:00
|
|
|
case VK_PACKET:
|
|
|
|
NewMsg.message = (lpMsg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
|
|
|
|
NewMsg.hwnd = lpMsg->hwnd;
|
|
|
|
NewMsg.wParam = HIWORD(lpMsg->lParam);
|
|
|
|
NewMsg.lParam = LOWORD(lpMsg->lParam);
|
|
|
|
MsqPostMessage(pti->MessageQueue, &NewMsg, FALSE, QS_KEY);
|
|
|
|
return TRUE;
|
2009-10-26 08:50:00 +00:00
|
|
|
}
|
|
|
|
|
2011-09-09 16:17:02 +00:00
|
|
|
UState = ToUnicodeInner( lpMsg->wParam,
|
|
|
|
HIWORD(lpMsg->lParam) & 0xff,
|
|
|
|
gKeyStateTable,
|
|
|
|
wp,
|
|
|
|
2,
|
|
|
|
0,
|
|
|
|
keyLayout );
|
|
|
|
|
|
|
|
if (UState == 1)
|
|
|
|
{
|
|
|
|
NewMsg.message = (lpMsg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
|
|
|
|
if (dead_char)
|
|
|
|
{
|
|
|
|
ULONG i;
|
|
|
|
WCHAR first, second;
|
|
|
|
TRACE("PREVIOUS DEAD CHAR: %c\n", dead_char);
|
|
|
|
|
|
|
|
for( i = 0; keyLayout->pDeadKey[i].dwBoth; i++ )
|
2005-09-07 21:25:42 +00:00
|
|
|
{
|
2011-09-09 16:17:02 +00:00
|
|
|
first = keyLayout->pDeadKey[i].dwBoth >> 16;
|
|
|
|
second = keyLayout->pDeadKey[i].dwBoth;
|
|
|
|
if (first == dead_char && second == wp[0])
|
|
|
|
{
|
|
|
|
wp[0] = keyLayout->pDeadKey[i].wchComposed;
|
|
|
|
dead_char = 0;
|
|
|
|
break;
|
|
|
|
}
|
2005-09-07 21:25:42 +00:00
|
|
|
}
|
2011-09-09 16:17:02 +00:00
|
|
|
|
|
|
|
TRACE("FINAL CHAR: %c\n", wp[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dead_char)
|
|
|
|
{
|
|
|
|
NewMsg.hwnd = lpMsg->hwnd;
|
|
|
|
NewMsg.wParam = dead_char;
|
|
|
|
NewMsg.lParam = lpMsg->lParam;
|
|
|
|
dead_char = 0;
|
|
|
|
MsqPostMessage(pti->MessageQueue, &NewMsg, FALSE, QS_KEY);
|
|
|
|
}
|
|
|
|
|
|
|
|
NewMsg.hwnd = lpMsg->hwnd;
|
|
|
|
NewMsg.wParam = wp[0];
|
|
|
|
NewMsg.lParam = lpMsg->lParam;
|
|
|
|
TRACE( "CHAR='%c' %04x %08x\n", wp[0], wp[0], lpMsg->lParam );
|
|
|
|
MsqPostMessage(pti->MessageQueue, &NewMsg, FALSE, QS_KEY);
|
|
|
|
Result = TRUE;
|
|
|
|
}
|
|
|
|
else if (UState == -1)
|
|
|
|
{
|
|
|
|
NewMsg.message =
|
|
|
|
(lpMsg->message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
|
|
|
|
NewMsg.hwnd = lpMsg->hwnd;
|
|
|
|
NewMsg.wParam = wp[0];
|
|
|
|
NewMsg.lParam = lpMsg->lParam;
|
|
|
|
dead_char = wp[0];
|
|
|
|
MsqPostMessage(pti->MessageQueue, &NewMsg, FALSE, QS_KEY);
|
|
|
|
Result = TRUE;
|
|
|
|
}
|
|
|
|
TRACE("IntTranslateKbdMessage E %s\n", NewMsg.message == WM_CHAR ? "WM_CHAR" : "WM_SYSCHAR");
|
|
|
|
return Result;
|
2002-01-27 14:47:44 +00:00
|
|
|
}
|
2003-07-05 16:04:01 +00:00
|
|
|
|
2005-09-07 21:25:42 +00:00
|
|
|
static UINT VkToScan( UINT Code, BOOL ExtCode, PKBDTABLES pkKT )
|
|
|
|
{
|
2011-09-09 16:17:02 +00:00
|
|
|
int i;
|
2003-10-09 06:13:05 +00:00
|
|
|
|
2011-09-09 16:17:02 +00:00
|
|
|
for( i = 0; i < pkKT->bMaxVSCtoVK; i++ )
|
|
|
|
{
|
|
|
|
if( pkKT->pusVSCtoVK[i] == Code )
|
|
|
|
{
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
2003-10-09 06:13:05 +00:00
|
|
|
|
2011-09-09 16:17:02 +00:00
|
|
|
return 0;
|
2003-10-09 06:13:05 +00:00
|
|
|
}
|
|
|
|
|
2005-09-07 21:25:42 +00:00
|
|
|
UINT ScanToVk( UINT Code, BOOL ExtKey, PKBDTABLES pkKT )
|
|
|
|
{
|
2011-09-09 16:17:02 +00:00
|
|
|
if( !pkKT )
|
|
|
|
{
|
|
|
|
TRACE("ScanToVk: No layout\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ExtKey )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for( i = 0; pkKT->pVSCtoVK_E0[i].Vsc; i++ )
|
|
|
|
{
|
|
|
|
if( pkKT->pVSCtoVK_E0[i].Vsc == Code )
|
|
|
|
return pkKT->pVSCtoVK_E0[i].Vk & 0xff;
|
|
|
|
}
|
|
|
|
for( i = 0; pkKT->pVSCtoVK_E1[i].Vsc; i++ )
|
|
|
|
{
|
|
|
|
if( pkKT->pVSCtoVK_E1[i].Vsc == Code )
|
|
|
|
return pkKT->pVSCtoVK_E1[i].Vk & 0xff;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( Code >= pkKT->bMaxVSCtoVK )
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return pkKT->pusVSCtoVK[Code] & 0xff;
|
|
|
|
}
|
2003-10-09 06:13:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Map a virtual key code, or virtual scan code, to a scan code, key code,
|
|
|
|
* or unshifted unicode character.
|
|
|
|
*
|
|
|
|
* Code: See Below
|
|
|
|
* Type:
|
|
|
|
* 0 -- Code is a virtual key code that is converted into a virtual scan code
|
|
|
|
* that does not distinguish between left and right shift keys.
|
|
|
|
* 1 -- Code is a virtual scan code that is converted into a virtual key code
|
|
|
|
* that does not distinguish between left and right shift keys.
|
|
|
|
* 2 -- Code is a virtual key code that is converted into an unshifted unicode
|
|
|
|
* character.
|
|
|
|
* 3 -- Code is a virtual scan code that is converted into a virtual key code
|
|
|
|
* that distinguishes left and right shift keys.
|
|
|
|
* KeyLayout: Keyboard layout handle (currently, unused)
|
|
|
|
*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
|
2005-09-07 21:25:42 +00:00
|
|
|
static UINT IntMapVirtualKeyEx( UINT Code, UINT Type, PKBDTABLES keyLayout )
|
|
|
|
{
|
2011-09-09 16:17:02 +00:00
|
|
|
UINT ret = 0;
|
|
|
|
|
|
|
|
switch( Type )
|
|
|
|
{
|
|
|
|
case MAPVK_VK_TO_VSC:
|
|
|
|
if( Code == VK_SHIFT )
|
|
|
|
Code = VK_LSHIFT;
|
|
|
|
if( Code == VK_MENU )
|
|
|
|
Code = VK_LMENU;
|
|
|
|
if( Code == VK_CONTROL )
|
|
|
|
Code = VK_LCONTROL;
|
|
|
|
ret = VkToScan( Code, FALSE, keyLayout );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MAPVK_VSC_TO_VK:
|
|
|
|
ret =
|
|
|
|
DontDistinguishShifts
|
|
|
|
(IntMapVirtualKeyEx( Code, MAPVK_VSC_TO_VK_EX, keyLayout ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MAPVK_VK_TO_CHAR:
|
|
|
|
{
|
2005-09-27 10:52:10 +00:00
|
|
|
WCHAR wp[2] = {0};
|
2005-09-07 21:25:42 +00:00
|
|
|
|
|
|
|
ret = VkToScan( Code, FALSE, keyLayout );
|
|
|
|
ToUnicodeInner( Code, ret, 0, wp, 2, 0, keyLayout );
|
|
|
|
ret = wp[0];
|
2011-09-09 16:17:02 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MAPVK_VSC_TO_VK_EX:
|
|
|
|
|
|
|
|
ret = ScanToVk( Code, FALSE, keyLayout );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MAPVK_VK_TO_VSC_EX:
|
|
|
|
STUB;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ERR("Wrong type value: %u\n", Type);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2003-10-09 06:13:05 +00:00
|
|
|
}
|
|
|
|
|
2003-11-24 00:22:53 +00:00
|
|
|
UINT
|
2008-11-29 22:48:58 +00:00
|
|
|
APIENTRY
|
2005-09-07 21:25:42 +00:00
|
|
|
NtUserMapVirtualKeyEx( UINT Code, UINT Type, DWORD keyboardId, HKL dwhkl )
|
|
|
|
{
|
2011-09-09 16:17:02 +00:00
|
|
|
PTHREADINFO pti;
|
|
|
|
PKBDTABLES keyLayout;
|
|
|
|
DECLARE_RETURN(UINT);
|
2007-10-19 23:21:45 +00:00
|
|
|
|
2011-09-09 16:17:02 +00:00
|
|
|
TRACE("Enter NtUserMapVirtualKeyEx\n");
|
|
|
|
UserEnterExclusive();
|
2007-10-19 23:21:45 +00:00
|
|
|
|
2011-09-09 16:17:02 +00:00
|
|
|
pti = PsGetCurrentThreadWin32Thread();
|
|
|
|
keyLayout = pti ? pti->KeyboardLayout->KBTables : 0;
|
2003-11-24 00:22:53 +00:00
|
|
|
|
2011-09-09 16:17:02 +00:00
|
|
|
if( !keyLayout )
|
|
|
|
RETURN(0);
|
2003-11-24 00:22:53 +00:00
|
|
|
|
2011-09-09 16:17:02 +00:00
|
|
|
RETURN(IntMapVirtualKeyEx( Code, Type, keyLayout ));
|
2007-10-19 23:21:45 +00:00
|
|
|
|
2005-09-08 16:18:51 +00:00
|
|
|
CLEANUP:
|
2011-09-09 16:17:02 +00:00
|
|
|
TRACE("Leave NtUserMapVirtualKeyEx, ret=%i\n", _ret_);
|
|
|
|
UserLeave();
|
|
|
|
END_CLEANUP;
|
2003-11-24 00:22:53 +00:00
|
|
|
}
|
|
|
|
|
2003-10-09 06:13:05 +00:00
|
|
|
|
|
|
|
int
|
2008-11-29 22:48:58 +00:00
|
|
|
APIENTRY
|
2003-10-09 06:13:05 +00:00
|
|
|
NtUserToUnicodeEx(
|
2011-09-09 16:17:02 +00:00
|
|
|
UINT wVirtKey,
|
|
|
|
UINT wScanCode,
|
|
|
|
PBYTE lpKeyState,
|
|
|
|
LPWSTR pwszBuff,
|
|
|
|
int cchBuff,
|
|
|
|
UINT wFlags,
|
|
|
|
HKL dwhkl )
|
2005-09-07 21:25:42 +00:00
|
|
|
{
|
2011-09-09 16:17:02 +00:00
|
|
|
PTHREADINFO pti;
|
|
|
|
BYTE KeyStateBuf[0x100];
|
|
|
|
PWCHAR OutPwszBuff = 0;
|
|
|
|
int ret = 0;
|
|
|
|
DECLARE_RETURN(int);
|
|
|
|
|
|
|
|
TRACE("Enter NtUserSetKeyboardState\n");
|
|
|
|
UserEnterShared();//fixme: this syscall doesnt seem to need any locking...
|
|
|
|
|
|
|
|
/* Key up? */
|
|
|
|
if (wScanCode & SC_KEY_UP)
|
|
|
|
{
|
|
|
|
RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !NT_SUCCESS(MmCopyFromCaller(KeyStateBuf,
|
|
|
|
lpKeyState,
|
|
|
|
sizeof(KeyStateBuf))) )
|
|
|
|
{
|
|
|
|
ERR( "Couldn't copy key state from caller.\n" );
|
|
|
|
RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Virtual code is correct? */
|
|
|
|
if (wVirtKey < 0x100)
|
|
|
|
{
|
|
|
|
OutPwszBuff = ExAllocatePoolWithTag(NonPagedPool, sizeof(WCHAR) * cchBuff, TAG_STRING);
|
|
|
|
if( !OutPwszBuff )
|
|
|
|
{
|
|
|
|
ERR( "ExAllocatePoolWithTag(%d) failed\n", sizeof(WCHAR) * cchBuff);
|
|
|
|
RETURN(0);
|
|
|
|
}
|
|
|
|
RtlZeroMemory( OutPwszBuff, sizeof( WCHAR ) * cchBuff );
|
|
|
|
|
|
|
|
pti = PsGetCurrentThreadWin32Thread();
|
|
|
|
ret = ToUnicodeInner( wVirtKey,
|
|
|
|
wScanCode,
|
|
|
|
KeyStateBuf,
|
|
|
|
OutPwszBuff,
|
|
|
|
cchBuff,
|
|
|
|
wFlags,
|
|
|
|
pti ? pti->KeyboardLayout->KBTables : 0 );
|
|
|
|
|
|
|
|
MmCopyToCaller(pwszBuff, OutPwszBuff, sizeof(WCHAR)*cchBuff);
|
|
|
|
ExFreePoolWithTag(OutPwszBuff, TAG_STRING);
|
|
|
|
}
|
|
|
|
|
|
|
|
RETURN(ret);
|
2007-10-19 23:21:45 +00:00
|
|
|
|
2005-09-08 16:18:51 +00:00
|
|
|
CLEANUP:
|
2011-09-09 16:17:02 +00:00
|
|
|
TRACE("Leave NtUserSetKeyboardState, ret=%i\n", _ret_);
|
|
|
|
UserLeave();
|
|
|
|
END_CLEANUP;
|
2003-10-09 06:13:05 +00:00
|
|
|
}
|
|
|
|
|
2005-09-07 21:25:42 +00:00
|
|
|
static int W32kSimpleToupper( int ch )
|
|
|
|
{
|
2011-09-09 16:17:02 +00:00
|
|
|
if( ch >= 'a' && ch <= 'z' )
|
|
|
|
ch = ch - 'a' + 'A';
|
|
|
|
return ch;
|
2003-10-09 06:13:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DWORD
|
2008-11-29 22:48:58 +00:00
|
|
|
APIENTRY
|
2005-09-07 21:25:42 +00:00
|
|
|
NtUserGetKeyNameText( LONG lParam, LPWSTR lpString, int nSize )
|
|
|
|
{
|
2011-09-09 16:17:02 +00:00
|
|
|
PTHREADINFO pti;
|
|
|
|
int i;
|
|
|
|
DWORD ret = 0;
|
|
|
|
UINT CareVk = 0;
|
|
|
|
UINT VkCode = 0;
|
|
|
|
UINT ScanCode = (lParam >> 16) & 0xff;
|
|
|
|
BOOL ExtKey = lParam & (1 << 24) ? TRUE : FALSE;
|
|
|
|
PKBDTABLES keyLayout;
|
|
|
|
VSC_LPWSTR *KeyNames;
|
|
|
|
DECLARE_RETURN(DWORD);
|
|
|
|
|
|
|
|
TRACE("Enter NtUserGetKeyNameText\n");
|
|
|
|
UserEnterShared();
|
|
|
|
|
|
|
|
pti = PsGetCurrentThreadWin32Thread();
|
|
|
|
keyLayout = pti ? pti->KeyboardLayout->KBTables : 0;
|
|
|
|
|
|
|
|
if( !keyLayout || nSize < 1 )
|
|
|
|
RETURN(0);
|
|
|
|
|
|
|
|
if( lParam & (1 << 25) )
|
|
|
|
{
|
|
|
|
CareVk = VkCode = ScanToVk( ScanCode, ExtKey, keyLayout );
|
|
|
|
switch (VkCode)
|
|
|
|
{
|
|
|
|
case VK_RSHIFT:
|
|
|
|
ScanCode |= 0x100;
|
|
|
|
case VK_LSHIFT:
|
|
|
|
VkCode = VK_SHIFT;
|
|
|
|
break;
|
|
|
|
case VK_LCONTROL:
|
|
|
|
case VK_RCONTROL:
|
|
|
|
VkCode = VK_CONTROL;
|
|
|
|
break;
|
|
|
|
case VK_LMENU:
|
|
|
|
case VK_RMENU:
|
|
|
|
VkCode = VK_MENU;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
VkCode = ScanToVk( ScanCode, ExtKey, keyLayout );
|
|
|
|
}
|
2003-10-09 06:13:05 +00:00
|
|
|
|
2011-09-09 16:17:02 +00:00
|
|
|
KeyNames = 0;
|
2003-10-09 06:13:05 +00:00
|
|
|
|
2011-09-09 16:17:02 +00:00
|
|
|
if( CareVk != VkCode )
|
|
|
|
ScanCode = VkToScan( VkCode, ExtKey, keyLayout );
|
2003-10-09 06:13:05 +00:00
|
|
|
|
2011-09-09 16:17:02 +00:00
|
|
|
if( ExtKey )
|
|
|
|
KeyNames = keyLayout->pKeyNamesExt;
|
|
|
|
else
|
|
|
|
KeyNames = keyLayout->pKeyNames;
|
|
|
|
|
|
|
|
for( i = 0; KeyNames[i].pwsz; i++ )
|
|
|
|
{
|
|
|
|
if( KeyNames[i].vsc == ScanCode )
|
|
|
|
{
|
|
|
|
UINT StrLen = wcslen(KeyNames[i].pwsz);
|
|
|
|
UINT StrMax = StrLen > (nSize - 1) ? (nSize - 1) : StrLen;
|
|
|
|
WCHAR null_wc = 0;
|
|
|
|
if( NT_SUCCESS( MmCopyToCaller( lpString,
|
|
|
|
KeyNames[i].pwsz,
|
|
|
|
StrMax * sizeof(WCHAR) ) ) &&
|
|
|
|
NT_SUCCESS( MmCopyToCaller( lpString + StrMax,
|
|
|
|
&null_wc,
|
|
|
|
sizeof( WCHAR ) ) ) )
|
|
|
|
{
|
|
|
|
ret = StrMax;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ret == 0 )
|
|
|
|
{
|
|
|
|
WCHAR UCName[2];
|
|
|
|
|
|
|
|
UCName[0] = W32kSimpleToupper(IntMapVirtualKeyEx( VkCode, MAPVK_VK_TO_CHAR, keyLayout ));
|
|
|
|
UCName[1] = 0;
|
|
|
|
ret = 1;
|
|
|
|
|
|
|
|
if( !NT_SUCCESS(MmCopyToCaller( lpString, UCName, 2 * sizeof(WCHAR) )) )
|
|
|
|
RETURN(0);
|
|
|
|
}
|
2003-10-09 06:13:05 +00:00
|
|
|
|
2011-09-09 16:17:02 +00:00
|
|
|
RETURN(ret);
|
2007-10-19 23:21:45 +00:00
|
|
|
|
2005-09-08 16:18:51 +00:00
|
|
|
CLEANUP:
|
2011-09-09 16:17:02 +00:00
|
|
|
TRACE("Leave NtUserGetKeyNameText, ret=%i\n", _ret_);
|
|
|
|
UserLeave();
|
|
|
|
END_CLEANUP;
|
2003-10-09 06:13:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Filter this message according to the current key layout, setting wParam
|
|
|
|
* appropriately.
|
|
|
|
*/
|
|
|
|
|
2005-08-06 18:56:20 +00:00
|
|
|
VOID FASTCALL
|
|
|
|
W32kKeyProcessMessage(LPMSG Msg,
|
|
|
|
PKBDTABLES KeyboardLayout,
|
|
|
|
BYTE Prefix)
|
|
|
|
{
|
2011-09-09 16:17:02 +00:00
|
|
|
DWORD ScanCode = 0, ModifierBits = 0;
|
|
|
|
DWORD i = 0;
|
|
|
|
DWORD BaseMapping = 0;
|
|
|
|
DWORD RawVk = 0;
|
|
|
|
static WORD NumpadConversion[][2] =
|
|
|
|
{ { VK_DELETE, VK_DECIMAL },
|
2005-09-07 21:25:42 +00:00
|
|
|
{ VK_INSERT, VK_NUMPAD0 },
|
|
|
|
{ VK_END, VK_NUMPAD1 },
|
|
|
|
{ VK_DOWN, VK_NUMPAD2 },
|
|
|
|
{ VK_NEXT, VK_NUMPAD3 },
|
|
|
|
{ VK_LEFT, VK_NUMPAD4 },
|
|
|
|
{ VK_CLEAR, VK_NUMPAD5 },
|
|
|
|
{ VK_RIGHT, VK_NUMPAD6 },
|
|
|
|
{ VK_HOME, VK_NUMPAD7 },
|
|
|
|
{ VK_UP, VK_NUMPAD8 },
|
|
|
|
{ VK_PRIOR, VK_NUMPAD9 },
|
2011-09-09 16:17:02 +00:00
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
PVSC_VK VscVkTable = NULL;
|
|
|
|
|
|
|
|
if( !KeyboardLayout || !Msg ||
|
|
|
|
(Msg->message != WM_KEYDOWN && Msg->message != WM_SYSKEYDOWN &&
|
|
|
|
Msg->message != WM_KEYUP && Msg->message != WM_SYSKEYUP) )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* arty -- handle numpad -- On real windows, the actual key produced
|
|
|
|
* by the messaging layer is different based on the state of numlock. */
|
|
|
|
ModifierBits = ModBits(KeyboardLayout, gKeyStateTable);
|
|
|
|
|
|
|
|
/* Get the raw scan code, so we can look up whether the key is a numpad
|
|
|
|
* key
|
|
|
|
*
|
|
|
|
* Shift and the LP_EXT_BIT cancel. */
|
|
|
|
ScanCode = (Msg->lParam >> 16) & 0xff;
|
|
|
|
TRACE("ScanCode %04x\n", ScanCode);
|
|
|
|
|
|
|
|
BaseMapping = Msg->wParam =
|
|
|
|
IntMapVirtualKeyEx( ScanCode, MAPVK_VSC_TO_VK, KeyboardLayout );
|
|
|
|
if( Prefix == 0 )
|
|
|
|
{
|
|
|
|
if( ScanCode >= KeyboardLayout->bMaxVSCtoVK )
|
|
|
|
RawVk = 0xff;
|
|
|
|
else
|
|
|
|
RawVk = KeyboardLayout->pusVSCtoVK[ScanCode];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( Prefix == 0xE0 )
|
|
|
|
{
|
|
|
|
/* ignore shift codes */
|
|
|
|
if( ScanCode == 0x2A || ScanCode == 0x36 )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
VscVkTable = KeyboardLayout->pVSCtoVK_E0;
|
|
|
|
}
|
|
|
|
else if( Prefix == 0xE1 )
|
|
|
|
{
|
|
|
|
VscVkTable = KeyboardLayout->pVSCtoVK_E1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!VscVkTable)
|
|
|
|
{
|
|
|
|
ERR("somethings wrong, Prefix=0x%x", Prefix);
|
2005-09-07 21:25:42 +00:00
|
|
|
return;
|
2011-09-09 16:17:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RawVk = 0xff;
|
|
|
|
while (VscVkTable->Vsc)
|
|
|
|
{
|
|
|
|
if( VscVkTable->Vsc == ScanCode )
|
|
|
|
{
|
|
|
|
RawVk = VscVkTable->Vk;
|
|
|
|
}
|
|
|
|
VscVkTable++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((ModifierBits & NUMLOCK_BIT) &&
|
|
|
|
!(ModifierBits & GetShiftBit(KeyboardLayout, VK_SHIFT)) &&
|
|
|
|
(RawVk & KNUMP) &&
|
|
|
|
!(Msg->lParam & LP_EXT_BIT))
|
|
|
|
{
|
|
|
|
/* The key in question is a numpad key. Search for a translation. */
|
|
|
|
for (i = 0; NumpadConversion[i][0]; i++)
|
|
|
|
{
|
|
|
|
if ((BaseMapping & 0xff) == NumpadConversion[i][0]) /* RawVk? */
|
|
|
|
{
|
|
|
|
Msg->wParam = NumpadConversion[i][1];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Key: [%04x -> %04x]\n", BaseMapping, Msg->wParam);
|
|
|
|
|
|
|
|
/* Now that we have the VK, we can set the keymap appropriately
|
|
|
|
* This is a better place for this code, as it's guaranteed to be
|
|
|
|
* run, unlike translate message. */
|
|
|
|
if (Msg->message == WM_KEYDOWN || Msg->message == WM_SYSKEYDOWN)
|
|
|
|
{
|
|
|
|
SetKeyState( ScanCode, Msg->wParam, Msg->lParam & LP_EXT_BIT,
|
|
|
|
TRUE ); /* Strike key */
|
|
|
|
}
|
|
|
|
else if (Msg->message == WM_KEYUP || Msg->message == WM_SYSKEYUP)
|
|
|
|
{
|
|
|
|
SetKeyState( ScanCode, Msg->wParam, Msg->lParam & LP_EXT_BIT,
|
|
|
|
FALSE ); /* Release key */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We need to unset SYSKEYDOWN if the ALT key is an ALT+Gr */
|
|
|
|
if( gKeyStateTable[VK_RMENU] & KS_DOWN_BIT )
|
|
|
|
{
|
|
|
|
if( Msg->message == WM_SYSKEYDOWN )
|
|
|
|
Msg->message = WM_KEYDOWN;
|
|
|
|
else
|
|
|
|
Msg->message = WM_KEYUP;
|
|
|
|
}
|
2004-02-19 06:59:50 +00:00
|
|
|
|
2003-11-24 00:22:53 +00:00
|
|
|
}
|
2005-07-13 23:19:59 +00:00
|
|
|
|
2005-09-07 21:25:42 +00:00
|
|
|
|
|
|
|
|
2005-09-05 21:19:23 +00:00
|
|
|
DWORD FASTCALL
|
|
|
|
UserGetKeyboardType(
|
2011-09-09 16:17:02 +00:00
|
|
|
DWORD TypeFlag)
|
2005-07-13 23:19:59 +00:00
|
|
|
{
|
2011-09-09 16:17:02 +00:00
|
|
|
switch(TypeFlag)
|
|
|
|
{
|
|
|
|
case 0: /* Keyboard type */
|
|
|
|
return 4; /* AT-101 */
|
|
|
|
case 1: /* Keyboard Subtype */
|
|
|
|
return 0; /* There are no defined subtypes */
|
|
|
|
case 2: /* Number of F-keys */
|
|
|
|
return 12; /* We're doing an 101 for now, so return 12 F-keys */
|
|
|
|
default:
|
|
|
|
ERR("Unknown type!\n");
|
|
|
|
return 0; /* The book says 0 here, so 0 */
|
|
|
|
}
|
2005-09-07 21:25:42 +00:00
|
|
|
}
|
|
|
|
|
2006-09-07 19:23:39 +00:00
|
|
|
|
2005-07-13 23:19:59 +00:00
|
|
|
/*
|
|
|
|
Based on TryToTranslateChar, instead of processing VirtualKey match,
|
|
|
|
look for wChar match.
|
|
|
|
*/
|
|
|
|
DWORD
|
2008-11-29 22:48:58 +00:00
|
|
|
APIENTRY
|
2005-07-13 23:19:59 +00:00
|
|
|
NtUserVkKeyScanEx(
|
2011-09-09 16:17:02 +00:00
|
|
|
WCHAR wChar,
|
|
|
|
HKL hKeyboardLayout,
|
|
|
|
BOOL UsehKL ) // TRUE from KeyboardLayout, FALSE from pkbl = (THREADINFO)->KeyboardLayout
|
2005-07-13 23:19:59 +00:00
|
|
|
{
|
2011-09-09 16:17:02 +00:00
|
|
|
PKBDTABLES KeyLayout;
|
|
|
|
PVK_TO_WCHAR_TABLE vtwTbl;
|
|
|
|
PVK_TO_WCHARS10 vkPtr;
|
|
|
|
size_t size_this_entry;
|
|
|
|
int nMod;
|
|
|
|
PKBL pkbl = NULL;
|
|
|
|
DWORD CapsMod = 0, CapsState = 0, Ret = -1;
|
|
|
|
|
|
|
|
TRACE("NtUserVkKeyScanEx() wChar %d, KbdLayout 0x%p\n", wChar, hKeyboardLayout);
|
|
|
|
UserEnterShared();
|
|
|
|
|
|
|
|
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++)
|
|
|
|
{
|
|
|
|
vtwTbl = &KeyLayout->pVkToWcharTable[nMod];
|
|
|
|
size_this_entry = vtwTbl->cbSize;
|
|
|
|
vkPtr = (PVK_TO_WCHARS10)((BYTE *)vtwTbl->pVkToWchars);
|
|
|
|
|
|
|
|
while(vkPtr->VirtualKey)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
0x01 Shift key
|
|
|
|
0x02 Ctrl key
|
|
|
|
0x04 Alt key
|
|
|
|
Should have only 8 valid possibilities. Including zero.
|
|
|
|
*/
|
|
|
|
for(CapsState = 0; CapsState < vtwTbl->nModifications; CapsState++)
|
2005-09-07 21:25:42 +00:00
|
|
|
{
|
2011-09-09 16:17:02 +00:00
|
|
|
if(vkPtr->wch[CapsState] == wChar)
|
|
|
|
{
|
|
|
|
CapsMod = KeyLayout->pCharModifiers->ModNumber[CapsState];
|
|
|
|
TRACE("nMod %d wC %04x: CapsMod %08x CapsState %08x MaxModBits %08x\n",
|
|
|
|
nMod, wChar, CapsMod, CapsState, KeyLayout->pCharModifiers->wMaxModBits);
|
|
|
|
Ret = ((CapsMod << 8) | (vkPtr->VirtualKey & 0xff));
|
|
|
|
goto Exit;
|
|
|
|
}
|
2005-09-07 21:25:42 +00:00
|
|
|
}
|
2011-09-09 16:17:02 +00:00
|
|
|
vkPtr = (PVK_TO_WCHARS10)(((BYTE *)vkPtr) + size_this_entry);
|
|
|
|
}
|
|
|
|
}
|
2009-05-22 01:35:48 +00:00
|
|
|
Exit:
|
2011-09-09 16:17:02 +00:00
|
|
|
UserLeave();
|
|
|
|
return Ret;
|
2005-07-13 23:19:59 +00:00
|
|
|
}
|
|
|
|
|
2005-09-07 21:25:42 +00:00
|
|
|
|
2003-05-18 17:16:18 +00:00
|
|
|
/* EOF */
|