2 * ReactOS W32 Subsystem
3 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS kernel
23 * FILE: subsys/win32k/ntuser/keyboard.c
24 * PROGRAMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
26 * 06-06-2001 CSH Created
29 /* INCLUDES ******************************************************************/
36 BYTE gQueueKeyStateTable
[256];
38 /* FUNCTIONS *****************************************************************/
40 /* Initialization -- Right now, just zero the key state and init the lock */
44 InitKeyboardImpl(VOID
)
46 RtlZeroMemory(&gQueueKeyStateTable
,0x100);
47 return STATUS_SUCCESS
;
50 /*** Statics used by TranslateMessage ***/
52 /*** Shift state code was out of hand, sorry. --- arty */
54 static UINT
DontDistinguishShifts( UINT ret
)
56 if( ret
== VK_LSHIFT
|| ret
== VK_RSHIFT
)
58 if( ret
== VK_LCONTROL
|| ret
== VK_RCONTROL
)
60 if( ret
== VK_LMENU
|| ret
== VK_RMENU
)
65 static VOID APIENTRY
SetKeyState(DWORD key
, DWORD vk
, DWORD ext
, BOOL down
)
69 /* Special handling for toggles like numpad and caps lock */
70 if (vk
== VK_CAPITAL
|| vk
== VK_NUMLOCK
)
73 gQueueKeyStateTable
[vk
] ^= KS_LOCK_BIT
;
77 vk
= ext
? VK_RSHIFT
: VK_LSHIFT
;
79 vk
= ext
? VK_RCONTROL
: VK_LCONTROL
;
81 vk
= ext
? VK_RMENU
: VK_LMENU
;
84 gQueueKeyStateTable
[vk
] |= KS_DOWN_BIT
;
86 gQueueKeyStateTable
[vk
] &= ~KS_DOWN_MASK
;
88 if (vk
== VK_LSHIFT
|| vk
== VK_RSHIFT
)
90 if ((gQueueKeyStateTable
[VK_LSHIFT
] & KS_DOWN_BIT
) ||
91 (gQueueKeyStateTable
[VK_RSHIFT
] & KS_DOWN_BIT
))
93 gQueueKeyStateTable
[VK_SHIFT
] |= KS_DOWN_BIT
;
97 gQueueKeyStateTable
[VK_SHIFT
] &= ~KS_DOWN_MASK
;
101 if (vk
== VK_LCONTROL
|| vk
== VK_RCONTROL
)
103 if ((gQueueKeyStateTable
[VK_LCONTROL
] & KS_DOWN_BIT
) ||
104 (gQueueKeyStateTable
[VK_RCONTROL
] & KS_DOWN_BIT
))
106 gQueueKeyStateTable
[VK_CONTROL
] |= KS_DOWN_BIT
;
110 gQueueKeyStateTable
[VK_CONTROL
] &= ~KS_DOWN_MASK
;
114 if (vk
== VK_LMENU
|| vk
== VK_RMENU
)
116 if ((gQueueKeyStateTable
[VK_LMENU
] & KS_DOWN_BIT
) ||
117 (gQueueKeyStateTable
[VK_RMENU
] & KS_DOWN_BIT
))
119 gQueueKeyStateTable
[VK_MENU
] |= KS_DOWN_BIT
;
123 gQueueKeyStateTable
[VK_MENU
] &= ~KS_DOWN_MASK
;
128 VOID
DumpKeyState( PBYTE KeyState
)
132 DbgPrint( "KeyState { " );
133 for( i
= 0; i
< 0x100; i
++ )
136 DbgPrint( "%02x(%02x) ", i
, KeyState
[i
] );
141 static BYTE
KeysSet( PKBDTABLES pkKT
, PBYTE KeyState
,
142 int FakeModLeft
, int FakeModRight
)
144 if( !KeyState
|| !pkKT
)
147 /* Search special codes first */
148 if( FakeModLeft
&& KeyState
[FakeModLeft
] )
149 return KeyState
[FakeModLeft
];
150 else if( FakeModRight
&& KeyState
[FakeModRight
] )
151 return KeyState
[FakeModRight
];
156 /* Search the keyboard layout modifiers table for the shift bit. I don't
157 * want to count on the shift bit not moving, because it can be specified
160 static DWORD FASTCALL
GetShiftBit( PKBDTABLES pkKT
, DWORD Vk
)
164 for( i
= 0; pkKT
->pCharModifiers
->pVkToBit
[i
].Vk
; i
++ )
165 if( pkKT
->pCharModifiers
->pVkToBit
[i
].Vk
== Vk
)
166 return pkKT
->pCharModifiers
->pVkToBit
[i
].ModBits
;
171 static DWORD
ModBits( PKBDTABLES pkKT
, PBYTE KeyState
)
178 /* DumpKeyState( KeyState ); */
180 if (KeysSet( pkKT
, KeyState
, VK_LSHIFT
, VK_RSHIFT
) &
182 ModBits
|= GetShiftBit( pkKT
, VK_SHIFT
);
184 if (KeysSet( pkKT
, KeyState
, VK_SHIFT
, 0 ) &
186 ModBits
|= GetShiftBit( pkKT
, VK_SHIFT
);
188 if (KeysSet( pkKT
, KeyState
, VK_LCONTROL
, VK_RCONTROL
) &
190 ModBits
|= GetShiftBit( pkKT
, VK_CONTROL
);
192 if (KeysSet( pkKT
, KeyState
, VK_CONTROL
, 0 ) &
194 ModBits
|= GetShiftBit( pkKT
, VK_CONTROL
);
196 if (KeysSet( pkKT
, KeyState
, VK_LMENU
, VK_RMENU
) &
198 ModBits
|= GetShiftBit( pkKT
, VK_MENU
);
201 if (pkKT
->fLocalFlags
& 0x1)
202 if (KeysSet( pkKT
, KeyState
, VK_RMENU
, 0 ) &
204 ModBits
|= GetShiftBit( pkKT
, VK_CONTROL
);
206 /* Deal with VK_CAPITAL */
207 if (KeysSet( pkKT
, KeyState
, VK_CAPITAL
, 0 ) & KS_LOCK_BIT
)
209 ModBits
|= CAPITAL_BIT
;
212 /* Deal with VK_NUMLOCK */
213 if (KeysSet( pkKT
, KeyState
, VK_NUMLOCK
, 0 ) & KS_LOCK_BIT
)
215 ModBits
|= NUMLOCK_BIT
;
218 DPRINT( "Current Mod Bits: %x\n", ModBits
);
223 static BOOL
TryToTranslateChar(WORD wVirtKey
,
227 PWCHAR pwcTranslatedChar
,
228 PKBDTABLES keyLayout
)
230 PVK_TO_WCHAR_TABLE vtwTbl
;
231 PVK_TO_WCHARS10 vkPtr
;
232 size_t size_this_entry
;
234 DWORD CapsMod
= 0, CapsState
= 0;
236 CapsState
= ModBits
& ~MOD_BITS_MASK
;
237 ModBits
= ModBits
& MOD_BITS_MASK
;
239 DPRINT ( "TryToTranslate: %04x %x\n", wVirtKey
, ModBits
);
241 if (ModBits
> keyLayout
->pCharModifiers
->wMaxModBits
)
246 for (nMod
= 0; keyLayout
->pVkToWcharTable
[nMod
].nModifications
; nMod
++)
248 vtwTbl
= &keyLayout
->pVkToWcharTable
[nMod
];
249 size_this_entry
= vtwTbl
->cbSize
;
250 vkPtr
= (PVK_TO_WCHARS10
)((BYTE
*)vtwTbl
->pVkToWchars
);
251 while(vkPtr
->VirtualKey
)
253 if( wVirtKey
== (vkPtr
->VirtualKey
& 0xff) )
255 CapsMod
= keyLayout
->pCharModifiers
->ModNumber
257 ((CapsState
& CAPITAL_BIT
) ? vkPtr
->Attributes
: 0)];
259 if( CapsMod
>= keyLayout
->pVkToWcharTable
[nMod
].nModifications
)
264 if( vkPtr
->wch
[CapsMod
] == WCH_NONE
)
269 *pbDead
= vkPtr
->wch
[CapsMod
] == WCH_DEAD
;
270 *pbLigature
= vkPtr
->wch
[CapsMod
] == WCH_LGTR
;
271 *pwcTranslatedChar
= vkPtr
->wch
[CapsMod
];
273 DPRINT("%d %04x: CapsMod %08x CapsState %08x Char %04x\n",
275 CapsMod
, CapsState
, *pwcTranslatedChar
);
279 vkPtr
= (PVK_TO_WCHARS10
)(((BYTE
*)vkPtr
) + size_this_entry
);
280 if( vkPtr
->VirtualKey
!= 0xff )
282 DPRINT( "Found dead key with no trailer in the table.\n" );
283 DPRINT( "VK: %04x, ADDR: %p\n", wVirtKey
, vkPtr
);
286 *pwcTranslatedChar
= vkPtr
->wch
[CapsMod
];
290 vkPtr
= (PVK_TO_WCHARS10
)(((BYTE
*)vkPtr
) + size_this_entry
);
298 ToUnicodeInner(UINT wVirtKey
,
306 WCHAR wcTranslatedChar
;
313 if( TryToTranslateChar( wVirtKey
,
314 ModBits( pkKT
, lpKeyState
),
322 DPRINT("Not handling ligature (yet)\n" );
327 pwszBuff
[0] = wcTranslatedChar
;
329 return bDead
? -1 : 1;
336 DWORD FASTCALL
UserGetAsyncKeyState(DWORD key
)
342 ret
= ((DWORD
)(gQueueKeyStateTable
[key
] & KS_DOWN_BIT
) << 8 ) |
343 (gQueueKeyStateTable
[key
] & KS_LOCK_BIT
);
349 /***********************************************************************
352 WORD FASTCALL
get_key_state(void)
356 if (gpsi
->aiSysMet
[SM_SWAPBUTTON
])
358 if (UserGetAsyncKeyState(VK_RBUTTON
) & 0x80) ret
|= MK_LBUTTON
;
359 if (UserGetAsyncKeyState(VK_LBUTTON
) & 0x80) ret
|= MK_RBUTTON
;
363 if (UserGetAsyncKeyState(VK_LBUTTON
) & 0x80) ret
|= MK_LBUTTON
;
364 if (UserGetAsyncKeyState(VK_RBUTTON
) & 0x80) ret
|= MK_RBUTTON
;
366 if (UserGetAsyncKeyState(VK_MBUTTON
) & 0x80) ret
|= MK_MBUTTON
;
367 if (UserGetAsyncKeyState(VK_SHIFT
) & 0x80) ret
|= MK_SHIFT
;
368 if (UserGetAsyncKeyState(VK_CONTROL
) & 0x80) ret
|= MK_CONTROL
;
369 if (UserGetAsyncKeyState(VK_XBUTTON1
) & 0x80) ret
|= MK_XBUTTON1
;
370 if (UserGetAsyncKeyState(VK_XBUTTON2
) & 0x80) ret
|= MK_XBUTTON2
;
376 NtUserGetAsyncKeyState(
379 DECLARE_RETURN(SHORT
);
381 DPRINT("Enter NtUserGetAsyncKeyState\n");
382 UserEnterExclusive();
384 RETURN((SHORT
)UserGetAsyncKeyState(key
));
387 DPRINT("Leave NtUserGetAsyncKeyState, ret=%i\n",_ret_
);
395 IntTranslateKbdMessage(LPMSG lpMsg
,
399 static INT dead_char
= 0;
403 PKBDTABLES keyLayout
;
406 pti
= PsGetCurrentThreadWin32Thread();
407 keyLayout
= pti
->KeyboardLayout
->KBTables
;
411 if (lpMsg
->message
< WM_KEYFIRST
|| lpMsg
->message
> WM_KEYLAST
)
413 if (lpMsg
->message
!= WM_KEYDOWN
&& lpMsg
->message
!= WM_SYSKEYDOWN
)
416 /* All messages have to contain the cursor point. */
417 NewMsg
.pt
= gpsi
->ptCursor
;
419 switch (lpMsg
->wParam
)
422 NewMsg
.message
= (lpMsg
->message
== WM_KEYDOWN
) ? WM_CHAR
: WM_SYSCHAR
;
423 NewMsg
.hwnd
= lpMsg
->hwnd
;
424 NewMsg
.wParam
= HIWORD(lpMsg
->lParam
);
425 NewMsg
.lParam
= LOWORD(lpMsg
->lParam
);
426 MsqPostMessage(pti
->MessageQueue
, &NewMsg
, FALSE
, QS_KEY
);
430 UState
= ToUnicodeInner(lpMsg
->wParam
, HIWORD(lpMsg
->lParam
) & 0xff,
431 gQueueKeyStateTable
, wp
, 2, 0,
436 NewMsg
.message
= (lpMsg
->message
== WM_KEYDOWN
) ? WM_CHAR
: WM_SYSCHAR
;
441 DPRINT("PREVIOUS DEAD CHAR: %c\n", dead_char
);
443 for( i
= 0; keyLayout
->pDeadKey
[i
].dwBoth
; i
++ )
445 first
= keyLayout
->pDeadKey
[i
].dwBoth
>> 16;
446 second
= keyLayout
->pDeadKey
[i
].dwBoth
;
447 if (first
== dead_char
&& second
== wp
[0])
449 wp
[0] = keyLayout
->pDeadKey
[i
].wchComposed
;
455 DPRINT("FINAL CHAR: %c\n", wp
[0]);
460 NewMsg
.hwnd
= lpMsg
->hwnd
;
461 NewMsg
.wParam
= dead_char
;
462 NewMsg
.lParam
= lpMsg
->lParam
;
464 MsqPostMessage(pti
->MessageQueue
, &NewMsg
, FALSE
, QS_KEY
);
467 NewMsg
.hwnd
= lpMsg
->hwnd
;
468 NewMsg
.wParam
= wp
[0];
469 NewMsg
.lParam
= lpMsg
->lParam
;
470 DPRINT( "CHAR='%c' %04x %08x\n", wp
[0], wp
[0], lpMsg
->lParam
);
471 MsqPostMessage(pti
->MessageQueue
, &NewMsg
, FALSE
, QS_KEY
);
474 else if (UState
== -1)
477 (lpMsg
->message
== WM_KEYDOWN
) ? WM_DEADCHAR
: WM_SYSDEADCHAR
;
478 NewMsg
.hwnd
= lpMsg
->hwnd
;
479 NewMsg
.wParam
= wp
[0];
480 NewMsg
.lParam
= lpMsg
->lParam
;
482 MsqPostMessage(pti
->MessageQueue
, &NewMsg
, FALSE
, QS_KEY
);
489 static UINT
VkToScan( UINT Code
, BOOL ExtCode
, PKBDTABLES pkKT
)
493 for( i
= 0; i
< pkKT
->bMaxVSCtoVK
; i
++ )
495 if( pkKT
->pusVSCtoVK
[i
] == Code
)
504 UINT
ScanToVk( UINT Code
, BOOL ExtKey
, PKBDTABLES pkKT
)
508 DPRINT("ScanToVk: No layout\n");
516 for( i
= 0; pkKT
->pVSCtoVK_E0
[i
].Vsc
; i
++ )
518 if( pkKT
->pVSCtoVK_E0
[i
].Vsc
== Code
)
519 return pkKT
->pVSCtoVK_E0
[i
].Vk
& 0xff;
521 for( i
= 0; pkKT
->pVSCtoVK_E1
[i
].Vsc
; i
++ )
523 if( pkKT
->pVSCtoVK_E1
[i
].Vsc
== Code
)
524 return pkKT
->pVSCtoVK_E1
[i
].Vk
& 0xff;
531 if( Code
>= pkKT
->bMaxVSCtoVK
)
535 return pkKT
->pusVSCtoVK
[Code
] & 0xff;
540 * Map a virtual key code, or virtual scan code, to a scan code, key code,
541 * or unshifted unicode character.
545 * 0 -- Code is a virtual key code that is converted into a virtual scan code
546 * that does not distinguish between left and right shift keys.
547 * 1 -- Code is a virtual scan code that is converted into a virtual key code
548 * that does not distinguish between left and right shift keys.
549 * 2 -- Code is a virtual key code that is converted into an unshifted unicode
551 * 3 -- Code is a virtual scan code that is converted into a virtual key code
552 * that distinguishes left and right shift keys.
553 * KeyLayout: Keyboard layout handle (currently, unused)
558 static UINT
IntMapVirtualKeyEx( UINT Code
, UINT Type
, PKBDTABLES keyLayout
)
565 if( Code
== VK_SHIFT
)
567 if( Code
== VK_MENU
)
569 if( Code
== VK_CONTROL
)
571 ret
= VkToScan( Code
, FALSE
, keyLayout
);
576 DontDistinguishShifts
577 (IntMapVirtualKeyEx( Code
, 3, keyLayout
) );
584 ret
= VkToScan( Code
, FALSE
, keyLayout
);
585 ToUnicodeInner( Code
, ret
, 0, wp
, 2, 0, keyLayout
);
592 ret
= ScanToVk( Code
, FALSE
, keyLayout
);
601 NtUserMapVirtualKeyEx( UINT Code
, UINT Type
, DWORD keyboardId
, HKL dwhkl
)
604 PKBDTABLES keyLayout
;
605 DECLARE_RETURN(UINT
);
607 DPRINT("Enter NtUserMapVirtualKeyEx\n");
608 UserEnterExclusive();
610 pti
= PsGetCurrentThreadWin32Thread();
611 keyLayout
= pti
? pti
->KeyboardLayout
->KBTables
: 0;
616 RETURN(IntMapVirtualKeyEx( Code
, Type
, keyLayout
));
619 DPRINT("Leave NtUserMapVirtualKeyEx, ret=%i\n",_ret_
);
637 BYTE KeyStateBuf
[0x100];
638 PWCHAR OutPwszBuff
= 0;
642 DPRINT("Enter NtUserSetKeyboardState\n");
643 UserEnterShared();//fixme: this syscall doesnt seem to need any locking...
646 if (wScanCode
& SC_KEY_UP
)
651 if( !NT_SUCCESS(MmCopyFromCaller(KeyStateBuf
,
653 sizeof(KeyStateBuf
))) )
655 DPRINT1( "Couldn't copy key state from caller.\n" );
659 /* Virtual code is correct? */
660 if (wVirtKey
< 0x100)
662 OutPwszBuff
= ExAllocatePoolWithTag(NonPagedPool
,sizeof(WCHAR
) * cchBuff
, TAG_STRING
);
665 DPRINT1( "ExAllocatePoolWithTag(%d) failed\n", sizeof(WCHAR
) * cchBuff
);
668 RtlZeroMemory( OutPwszBuff
, sizeof( WCHAR
) * cchBuff
);
670 pti
= PsGetCurrentThreadWin32Thread();
671 ret
= ToUnicodeInner( wVirtKey
,
677 pti
? pti
->KeyboardLayout
->KBTables
: 0 );
679 MmCopyToCaller(pwszBuff
,OutPwszBuff
,sizeof(WCHAR
)*cchBuff
);
680 ExFreePoolWithTag(OutPwszBuff
, TAG_STRING
);
686 DPRINT("Leave NtUserSetKeyboardState, ret=%i\n",_ret_
);
691 static int W32kSimpleToupper( int ch
)
693 if( ch
>= 'a' && ch
<= 'z' )
700 NtUserGetKeyNameText( LONG lParam
, LPWSTR lpString
, int nSize
)
707 UINT ScanCode
= (lParam
>> 16) & 0xff;
708 BOOL ExtKey
= lParam
& (1<<24) ? TRUE
: FALSE
;
709 PKBDTABLES keyLayout
;
710 VSC_LPWSTR
*KeyNames
;
711 DECLARE_RETURN(DWORD
);
713 DPRINT("Enter NtUserGetKeyNameText\n");
716 pti
= PsGetCurrentThreadWin32Thread();
717 keyLayout
= pti
? pti
->KeyboardLayout
->KBTables
: 0;
719 if( !keyLayout
|| nSize
< 1 )
722 if( lParam
& (1<<25) )
724 CareVk
= VkCode
= ScanToVk( ScanCode
, ExtKey
, keyLayout
);
744 VkCode
= ScanToVk( ScanCode
, ExtKey
, keyLayout
);
749 if( CareVk
!= VkCode
)
750 ScanCode
= VkToScan( VkCode
, ExtKey
, keyLayout
);
753 KeyNames
= keyLayout
->pKeyNamesExt
;
755 KeyNames
= keyLayout
->pKeyNames
;
757 for( i
= 0; KeyNames
[i
].pwsz
; i
++ )
759 if( KeyNames
[i
].vsc
== ScanCode
)
761 UINT StrLen
= wcslen(KeyNames
[i
].pwsz
);
762 UINT StrMax
= StrLen
> (nSize
- 1) ? (nSize
- 1) : StrLen
;
764 if( NT_SUCCESS( MmCopyToCaller( lpString
,
766 StrMax
* sizeof(WCHAR
) ) ) &&
767 NT_SUCCESS( MmCopyToCaller( lpString
+ StrMax
,
769 sizeof( WCHAR
) ) ) )
781 UCName
[0] = W32kSimpleToupper(IntMapVirtualKeyEx( VkCode
, 2, keyLayout
));
785 if( !NT_SUCCESS(MmCopyToCaller( lpString
, UCName
, 2 * sizeof(WCHAR
) )) )
792 DPRINT("Leave NtUserGetKeyNameText, ret=%i\n",_ret_
);
798 * Filter this message according to the current key layout, setting wParam
803 W32kKeyProcessMessage(LPMSG Msg
,
804 PKBDTABLES KeyboardLayout
,
807 DWORD ScanCode
= 0, ModifierBits
= 0;
809 DWORD BaseMapping
= 0;
811 static WORD NumpadConversion
[][2] =
812 { { VK_DELETE
, VK_DECIMAL
},
813 { VK_INSERT
, VK_NUMPAD0
},
814 { VK_END
, VK_NUMPAD1
},
815 { VK_DOWN
, VK_NUMPAD2
},
816 { VK_NEXT
, VK_NUMPAD3
},
817 { VK_LEFT
, VK_NUMPAD4
},
818 { VK_CLEAR
, VK_NUMPAD5
},
819 { VK_RIGHT
, VK_NUMPAD6
},
820 { VK_HOME
, VK_NUMPAD7
},
821 { VK_UP
, VK_NUMPAD8
},
822 { VK_PRIOR
, VK_NUMPAD9
},
824 PVSC_VK VscVkTable
= NULL
;
826 if( !KeyboardLayout
|| !Msg
||
827 (Msg
->message
!= WM_KEYDOWN
&& Msg
->message
!= WM_SYSKEYDOWN
&&
828 Msg
->message
!= WM_KEYUP
&& Msg
->message
!= WM_SYSKEYUP
) )
833 /* arty -- handle numpad -- On real windows, the actual key produced
834 * by the messaging layer is different based on the state of numlock. */
835 ModifierBits
= ModBits(KeyboardLayout
,gQueueKeyStateTable
);
837 /* Get the raw scan code, so we can look up whether the key is a numpad
840 * Shift and the LP_EXT_BIT cancel. */
841 ScanCode
= (Msg
->lParam
>> 16) & 0xff;
842 BaseMapping
= Msg
->wParam
=
843 IntMapVirtualKeyEx( ScanCode
, 1, KeyboardLayout
);
846 if( ScanCode
>= KeyboardLayout
->bMaxVSCtoVK
)
849 RawVk
= KeyboardLayout
->pusVSCtoVK
[ScanCode
];
855 /* ignore shift codes */
856 if( ScanCode
== 0x2A || ScanCode
== 0x36 )
860 VscVkTable
= KeyboardLayout
->pVSCtoVK_E0
;
862 else if( Prefix
== 0xE1 )
864 VscVkTable
= KeyboardLayout
->pVSCtoVK_E1
;
869 DPRINT1("somethings wrong, Prefix=0x%x", Prefix
);
874 while (VscVkTable
->Vsc
)
876 if( VscVkTable
->Vsc
== ScanCode
)
878 RawVk
= VscVkTable
->Vk
;
884 if ((ModifierBits
& NUMLOCK_BIT
) &&
885 !(ModifierBits
& GetShiftBit(KeyboardLayout
, VK_SHIFT
)) &&
887 !(Msg
->lParam
& LP_EXT_BIT
))
889 /* The key in question is a numpad key. Search for a translation. */
890 for (i
= 0; NumpadConversion
[i
][0]; i
++)
892 if ((BaseMapping
& 0xff) == NumpadConversion
[i
][0]) /* RawVk? */
894 Msg
->wParam
= NumpadConversion
[i
][1];
900 DPRINT("Key: [%04x -> %04x]\n", BaseMapping
, Msg
->wParam
);
902 /* Now that we have the VK, we can set the keymap appropriately
903 * This is a better place for this code, as it's guaranteed to be
904 * run, unlike translate message. */
905 if (Msg
->message
== WM_KEYDOWN
|| Msg
->message
== WM_SYSKEYDOWN
)
907 SetKeyState( ScanCode
, Msg
->wParam
, Msg
->lParam
& LP_EXT_BIT
,
908 TRUE
); /* Strike key */
910 else if (Msg
->message
== WM_KEYUP
|| Msg
->message
== WM_SYSKEYUP
)
912 SetKeyState( ScanCode
, Msg
->wParam
, Msg
->lParam
& LP_EXT_BIT
,
913 FALSE
); /* Release key */
916 /* We need to unset SYSKEYDOWN if the ALT key is an ALT+Gr */
917 if( gQueueKeyStateTable
[VK_RMENU
] & KS_DOWN_BIT
)
919 if( Msg
->message
== WM_SYSKEYDOWN
)
920 Msg
->message
= WM_KEYDOWN
;
922 Msg
->message
= WM_KEYUP
;
935 case 0: /* Keyboard type */
936 return 4; /* AT-101 */
937 case 1: /* Keyboard Subtype */
938 return 0; /* There are no defined subtypes */
939 case 2: /* Number of F-keys */
940 return 12; /* We're doing an 101 for now, so return 12 F-keys */
942 DPRINT1("Unknown type!\n");
943 return 0; /* The book says 0 here, so 0 */
949 Based on TryToTranslateChar, instead of processing VirtualKey match,
950 look for wChar match.
957 BOOL UsehKL
) // TRUE from KeyboardLayout, FALSE from pkbl = (THREADINFO)->KeyboardLayout
959 PKBDTABLES KeyLayout
;
960 PVK_TO_WCHAR_TABLE vtwTbl
;
961 PVK_TO_WCHARS10 vkPtr
;
962 size_t size_this_entry
;
965 DWORD CapsMod
= 0, CapsState
= 0, Ret
= -1;
967 DPRINT("NtUserVkKeyScanEx() wChar %d, KbdLayout 0x%p\n", wChar
, hKeyboardLayout
);
972 if ( !hKeyboardLayout
|| !(pkbl
= UserHklToKbl(hKeyboardLayout
)))
975 else // From VkKeyScanAW it is FALSE so KeyboardLayout is white noise.
977 pkbl
= ((PTHREADINFO
)PsGetCurrentThreadWin32Thread())->KeyboardLayout
;
980 KeyLayout
= pkbl
->KBTables
;
982 for (nMod
= 0; KeyLayout
->pVkToWcharTable
[nMod
].nModifications
; nMod
++)
984 vtwTbl
= &KeyLayout
->pVkToWcharTable
[nMod
];
985 size_this_entry
= vtwTbl
->cbSize
;
986 vkPtr
= (PVK_TO_WCHARS10
)((BYTE
*)vtwTbl
->pVkToWchars
);
988 while(vkPtr
->VirtualKey
)
994 Should have only 8 valid possibilities. Including zero.
996 for(CapsState
= 0; CapsState
< vtwTbl
->nModifications
; CapsState
++)
998 if(vkPtr
->wch
[CapsState
] == wChar
)
1000 CapsMod
= KeyLayout
->pCharModifiers
->ModNumber
[CapsState
];
1001 DPRINT("nMod %d wC %04x: CapsMod %08x CapsState %08x MaxModBits %08x\n",
1002 nMod
, wChar
, CapsMod
, CapsState
, KeyLayout
->pCharModifiers
->wMaxModBits
);
1003 Ret
= ((CapsMod
<< 8)|(vkPtr
->VirtualKey
& 0xff));
1007 vkPtr
= (PVK_TO_WCHARS10
)(((BYTE
*)vkPtr
) + size_this_entry
);