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
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, 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 ******************************************************************/
38 #define CAPITAL_BIT 0x80000000
39 #define NUMLOCK_BIT 0x40000000
40 #define MOD_BITS_MASK 0x3fffffff
41 #define MOD_KCTRL 0x02
43 #define KS_DOWN_MASK 0xc0
44 #define KS_DOWN_BIT 0x80
45 #define KS_LOCK_BIT 0x01
47 #define LP_EXT_BIT (1<<24)
48 /* From kbdxx.c -- Key changes with numlock */
52 BYTE gQueueKeyStateTable
[256];
56 /* FUNCTIONS *****************************************************************/
58 /* Initialization -- Right now, just zero the key state and init the lock */
59 NTSTATUS FASTCALL
InitKeyboardImpl(VOID
)
61 RtlZeroMemory(&gQueueKeyStateTable
,0x100);
62 return STATUS_SUCCESS
;
65 /*** Statics used by TranslateMessage ***/
67 /*** Shift state code was out of hand, sorry. --- arty */
69 static UINT
DontDistinguishShifts( UINT ret
)
71 if( ret
== VK_LSHIFT
|| ret
== VK_RSHIFT
)
73 if( ret
== VK_LCONTROL
|| ret
== VK_RCONTROL
)
75 if( ret
== VK_LMENU
|| ret
== VK_RMENU
)
80 static VOID STDCALL
SetKeyState(DWORD key
, DWORD vk
, DWORD ext
, BOOL down
)
84 /* Special handling for toggles like numpad and caps lock */
85 if (vk
== VK_CAPITAL
|| vk
== VK_NUMLOCK
)
88 gQueueKeyStateTable
[vk
] ^= KS_LOCK_BIT
;
91 if (ext
&& vk
== VK_LSHIFT
)
93 if (ext
&& vk
== VK_LCONTROL
)
95 if (ext
&& vk
== VK_LMENU
)
99 gQueueKeyStateTable
[vk
] |= KS_DOWN_BIT
;
101 gQueueKeyStateTable
[vk
] &= ~KS_DOWN_MASK
;
103 if (vk
== VK_LSHIFT
|| vk
== VK_RSHIFT
)
105 if ((gQueueKeyStateTable
[VK_LSHIFT
] & KS_DOWN_BIT
) ||
106 (gQueueKeyStateTable
[VK_RSHIFT
] & KS_DOWN_BIT
))
108 gQueueKeyStateTable
[VK_SHIFT
] |= KS_DOWN_BIT
;
112 gQueueKeyStateTable
[VK_SHIFT
] &= ~KS_DOWN_MASK
;
116 if (vk
== VK_LCONTROL
|| vk
== VK_RCONTROL
)
118 if ((gQueueKeyStateTable
[VK_LCONTROL
] & KS_DOWN_BIT
) ||
119 (gQueueKeyStateTable
[VK_RCONTROL
] & KS_DOWN_BIT
))
121 gQueueKeyStateTable
[VK_CONTROL
] |= KS_DOWN_BIT
;
125 gQueueKeyStateTable
[VK_CONTROL
] &= ~KS_DOWN_MASK
;
129 if (vk
== VK_LMENU
|| vk
== VK_RMENU
)
131 if ((gQueueKeyStateTable
[VK_LMENU
] & KS_DOWN_BIT
) ||
132 (gQueueKeyStateTable
[VK_RMENU
] & KS_DOWN_BIT
))
134 gQueueKeyStateTable
[VK_MENU
] |= KS_DOWN_BIT
;
138 gQueueKeyStateTable
[VK_MENU
] &= ~KS_DOWN_MASK
;
143 VOID
DumpKeyState( PBYTE KeyState
)
147 DbgPrint( "KeyState { " );
148 for( i
= 0; i
< 0x100; i
++ )
151 DbgPrint( "%02x(%02x) ", i
, KeyState
[i
] );
156 static BYTE
KeysSet( PKBDTABLES pkKT
, PBYTE KeyState
,
157 int FakeModLeft
, int FakeModRight
)
159 if( !KeyState
|| !pkKT
)
162 /* Search special codes first */
163 if( FakeModLeft
&& KeyState
[FakeModLeft
] )
164 return KeyState
[FakeModLeft
];
165 else if( FakeModRight
&& KeyState
[FakeModRight
] )
166 return KeyState
[FakeModRight
];
171 /* Search the keyboard layout modifiers table for the shift bit. I don't
172 * want to count on the shift bit not moving, because it can be specified
175 static DWORD FASTCALL
GetShiftBit( PKBDTABLES pkKT
, DWORD Vk
)
179 for( i
= 0; pkKT
->pCharModifiers
->pVkToBit
[i
].Vk
; i
++ )
180 if( pkKT
->pCharModifiers
->pVkToBit
[i
].Vk
== Vk
)
181 return pkKT
->pCharModifiers
->pVkToBit
[i
].ModBits
;
186 static DWORD
ModBits( PKBDTABLES pkKT
, PBYTE KeyState
)
193 /* DumpKeyState( KeyState ); */
195 if (KeysSet( pkKT
, KeyState
, VK_LSHIFT
, VK_RSHIFT
) &
197 ModBits
|= GetShiftBit( pkKT
, VK_SHIFT
);
199 if (KeysSet( pkKT
, KeyState
, VK_SHIFT
, 0 ) &
201 ModBits
|= GetShiftBit( pkKT
, VK_SHIFT
);
203 if (KeysSet( pkKT
, KeyState
, VK_LCONTROL
, VK_RCONTROL
) &
205 ModBits
|= GetShiftBit( pkKT
, VK_CONTROL
);
207 if (KeysSet( pkKT
, KeyState
, VK_CONTROL
, 0 ) &
209 ModBits
|= GetShiftBit( pkKT
, VK_CONTROL
);
211 if (KeysSet( pkKT
, KeyState
, VK_LMENU
, VK_RMENU
) &
213 ModBits
|= GetShiftBit( pkKT
, VK_MENU
);
216 if (KeysSet( pkKT
, KeyState
, VK_RMENU
, 0 ) &
218 ModBits
|= GetShiftBit( pkKT
, VK_CONTROL
);
220 /* Deal with VK_CAPITAL */
221 if (KeysSet( pkKT
, KeyState
, VK_CAPITAL
, 0 ) & KS_LOCK_BIT
)
223 ModBits
|= CAPITAL_BIT
;
226 /* Deal with VK_NUMLOCK */
227 if (KeysSet( pkKT
, KeyState
, VK_NUMLOCK
, 0 ) & KS_LOCK_BIT
)
229 ModBits
|= NUMLOCK_BIT
;
232 DPRINT( "Current Mod Bits: %x\n", ModBits
);
237 static BOOL
TryToTranslateChar(WORD wVirtKey
,
241 PWCHAR pwcTranslatedChar
,
242 PKBDTABLES keyLayout
)
244 PVK_TO_WCHAR_TABLE vtwTbl
;
245 PVK_TO_WCHARS10 vkPtr
;
246 size_t size_this_entry
;
248 DWORD CapsMod
= 0, CapsState
= 0;
250 CapsState
= ModBits
& ~MOD_BITS_MASK
;
251 ModBits
= ModBits
& MOD_BITS_MASK
;
253 DPRINT ( "TryToTranslate: %04x %x\n", wVirtKey
, ModBits
);
255 if (ModBits
> keyLayout
->pCharModifiers
->wMaxModBits
)
260 for (nMod
= 0; keyLayout
->pVkToWcharTable
[nMod
].nModifications
; nMod
++)
262 vtwTbl
= &keyLayout
->pVkToWcharTable
[nMod
];
263 size_this_entry
= vtwTbl
->cbSize
;
264 vkPtr
= (PVK_TO_WCHARS10
)((BYTE
*)vtwTbl
->pVkToWchars
);
265 while(vkPtr
->VirtualKey
)
267 if( wVirtKey
== (vkPtr
->VirtualKey
& 0xff) )
269 CapsMod
= keyLayout
->pCharModifiers
->ModNumber
271 ((CapsState
& CAPITAL_BIT
) ? vkPtr
->Attributes
: 0)];
273 if( CapsMod
>= keyLayout
->pVkToWcharTable
[nMod
].nModifications
)
278 if( vkPtr
->wch
[CapsMod
] == WCH_NONE
)
283 *pbDead
= vkPtr
->wch
[CapsMod
] == WCH_DEAD
;
284 *pbLigature
= vkPtr
->wch
[CapsMod
] == WCH_LGTR
;
285 *pwcTranslatedChar
= vkPtr
->wch
[CapsMod
];
287 DPRINT("%d %04x: CapsMod %08x CapsState %08x Char %04x\n",
289 CapsMod
, CapsState
, *pwcTranslatedChar
);
293 vkPtr
= (PVK_TO_WCHARS10
)(((BYTE
*)vkPtr
) + size_this_entry
);
294 if( vkPtr
->VirtualKey
!= 0xff )
296 DPRINT( "Found dead key with no trailer in the table.\n" );
297 DPRINT( "VK: %04x, ADDR: %08x\n", wVirtKey
, (int)vkPtr
);
300 *pwcTranslatedChar
= vkPtr
->wch
[CapsMod
];
304 vkPtr
= (PVK_TO_WCHARS10
)(((BYTE
*)vkPtr
) + size_this_entry
);
312 ToUnicodeInner(UINT wVirtKey
,
320 WCHAR wcTranslatedChar
;
327 if( TryToTranslateChar( wVirtKey
,
328 ModBits( pkKT
, lpKeyState
),
336 DPRINT("Not handling ligature (yet)\n" );
341 pwszBuff
[0] = wcTranslatedChar
;
343 return bDead
? -1 : 1;
350 DWORD FASTCALL
UserGetKeyState(DWORD key
)
356 ret
= ((DWORD
)(gQueueKeyStateTable
[key
] & KS_DOWN_BIT
) << 8 ) |
357 (gQueueKeyStateTable
[key
] & KS_LOCK_BIT
);
369 DECLARE_RETURN(DWORD
);
371 DPRINT("Enter NtUserGetKeyState\n");
372 UserEnterExclusive();
374 RETURN(UserGetKeyState(key
));
377 DPRINT("Leave NtUserGetKeyState, ret=%i\n",_ret_
);
384 DWORD FASTCALL
UserGetAsyncKeyState(DWORD key
)
390 ret
= ((DWORD
)(gQueueKeyStateTable
[key
] & KS_DOWN_BIT
) << 8 ) |
391 (gQueueKeyStateTable
[key
] & KS_LOCK_BIT
);
401 NtUserGetAsyncKeyState(
404 DECLARE_RETURN(DWORD
);
406 DPRINT("Enter NtUserGetAsyncKeyState\n");
407 UserEnterExclusive();
409 RETURN(UserGetAsyncKeyState(key
));
412 DPRINT("Leave NtUserGetAsyncKeyState, ret=%i\n",_ret_
);
420 IntTranslateKbdMessage(LPMSG lpMsg
,
423 static INT dead_char
= 0;
427 PKBDTABLES keyLayout
;
432 keyLayout
= PsGetCurrentThreadWin32Thread()->KeyboardLayout
->KBTables
;
436 if (lpMsg
->message
!= WM_KEYDOWN
&& lpMsg
->message
!= WM_SYSKEYDOWN
)
439 ScanCode
= (lpMsg
->lParam
>> 16) & 0xff;
441 /* All messages have to contain the cursor point. */
442 IntGetCursorLocation(PsGetCurrentThreadWin32Thread()->Desktop
->WindowStation
,
445 UState
= ToUnicodeInner(lpMsg
->wParam
, HIWORD(lpMsg
->lParam
) & 0xff,
446 gQueueKeyStateTable
, wp
, 2, 0,
451 NewMsg
.message
= (lpMsg
->message
== WM_KEYDOWN
) ? WM_CHAR
: WM_SYSCHAR
;
456 DPRINT("PREVIOUS DEAD CHAR: %c\n", dead_char
);
458 for( i
= 0; keyLayout
->pDeadKey
[i
].dwBoth
; i
++ )
460 first
= keyLayout
->pDeadKey
[i
].dwBoth
>> 16;
461 second
= keyLayout
->pDeadKey
[i
].dwBoth
;
462 if (first
== dead_char
&& second
== wp
[0])
464 wp
[0] = keyLayout
->pDeadKey
[i
].wchComposed
;
470 DPRINT("FINAL CHAR: %c\n", wp
[0]);
475 NewMsg
.hwnd
= lpMsg
->hwnd
;
476 NewMsg
.wParam
= dead_char
;
477 NewMsg
.lParam
= lpMsg
->lParam
;
479 MsqPostMessage(PsGetCurrentThreadWin32Thread()->MessageQueue
, &NewMsg
, FALSE
, QS_KEY
);
482 NewMsg
.hwnd
= lpMsg
->hwnd
;
483 NewMsg
.wParam
= wp
[0];
484 NewMsg
.lParam
= lpMsg
->lParam
;
485 DPRINT( "CHAR='%c' %04x %08x\n", wp
[0], wp
[0], lpMsg
->lParam
);
486 MsqPostMessage(PsGetCurrentThreadWin32Thread()->MessageQueue
, &NewMsg
, FALSE
, QS_KEY
);
489 else if (UState
== -1)
492 (lpMsg
->message
== WM_KEYDOWN
) ? WM_DEADCHAR
: WM_SYSDEADCHAR
;
493 NewMsg
.hwnd
= lpMsg
->hwnd
;
494 NewMsg
.wParam
= wp
[0];
495 NewMsg
.lParam
= lpMsg
->lParam
;
497 MsqPostMessage(PsGetCurrentThreadWin32Thread()->MessageQueue
, &NewMsg
, FALSE
, QS_KEY
);
506 NtUserGetKeyboardState(
510 DECLARE_RETURN(DWORD
);
512 DPRINT("Enter NtUserGetKeyboardState\n");
517 if(!NT_SUCCESS(MmCopyToCaller(lpKeyState
, gQueueKeyStateTable
, 256)))
524 DPRINT("Leave NtUserGetKeyboardState, ret=%i\n",_ret_
);
531 NtUserSetKeyboardState(LPBYTE lpKeyState
)
534 DECLARE_RETURN(DWORD
);
536 DPRINT("Enter NtUserSetKeyboardState\n");
537 UserEnterExclusive();
541 if(! NT_SUCCESS(MmCopyFromCaller(gQueueKeyStateTable
, lpKeyState
, 256)))
548 DPRINT("Leave NtUserSetKeyboardState, ret=%i\n",_ret_
);
553 static UINT
VkToScan( UINT Code
, BOOL ExtCode
, PKBDTABLES pkKT
)
557 for( i
= 0; i
< pkKT
->bMaxVSCtoVK
; i
++ )
559 if( pkKT
->pusVSCtoVK
[i
] == Code
)
568 UINT
ScanToVk( UINT Code
, BOOL ExtKey
, PKBDTABLES pkKT
)
572 DPRINT("ScanToVk: No layout\n");
580 for( i
= 0; pkKT
->pVSCtoVK_E0
[i
].Vsc
; i
++ )
582 if( pkKT
->pVSCtoVK_E0
[i
].Vsc
== Code
)
583 return pkKT
->pVSCtoVK_E0
[i
].Vk
& 0xff;
585 for( i
= 0; pkKT
->pVSCtoVK_E1
[i
].Vsc
; i
++ )
587 if( pkKT
->pVSCtoVK_E1
[i
].Vsc
== Code
)
588 return pkKT
->pVSCtoVK_E1
[i
].Vk
& 0xff;
595 if( Code
>= pkKT
->bMaxVSCtoVK
)
599 return pkKT
->pusVSCtoVK
[Code
] & 0xff;
604 * Map a virtual key code, or virtual scan code, to a scan code, key code,
605 * or unshifted unicode character.
609 * 0 -- Code is a virtual key code that is converted into a virtual scan code
610 * that does not distinguish between left and right shift keys.
611 * 1 -- Code is a virtual scan code that is converted into a virtual key code
612 * that does not distinguish between left and right shift keys.
613 * 2 -- Code is a virtual key code that is converted into an unshifted unicode
615 * 3 -- Code is a virtual scan code that is converted into a virtual key code
616 * that distinguishes left and right shift keys.
617 * KeyLayout: Keyboard layout handle (currently, unused)
622 static UINT
IntMapVirtualKeyEx( UINT Code
, UINT Type
, PKBDTABLES keyLayout
)
629 if( Code
== VK_RSHIFT
)
631 if( Code
== VK_RMENU
)
633 if( Code
== VK_RCONTROL
)
635 ret
= VkToScan( Code
, FALSE
, keyLayout
);
640 DontDistinguishShifts
641 (IntMapVirtualKeyEx( Code
, 3, keyLayout
) );
648 ret
= VkToScan( Code
, FALSE
, keyLayout
);
649 ToUnicodeInner( Code
, ret
, 0, wp
, 2, 0, keyLayout
);
656 ret
= ScanToVk( Code
, FALSE
, keyLayout
);
665 NtUserMapVirtualKeyEx( UINT Code
, UINT Type
, DWORD keyboardId
, HKL dwhkl
)
667 PKBDTABLES keyLayout
;
668 DECLARE_RETURN(UINT
);
670 DPRINT("Enter NtUserMapVirtualKeyEx\n");
671 UserEnterExclusive();
673 keyLayout
= PsGetCurrentThreadWin32Thread() ? PsGetCurrentThreadWin32Thread()->KeyboardLayout
->KBTables
: 0;
678 RETURN(IntMapVirtualKeyEx( Code
, Type
, keyLayout
));
681 DPRINT("Leave NtUserMapVirtualKeyEx, ret=%i\n",_ret_
);
698 BYTE KeyStateBuf
[0x100];
699 PWCHAR OutPwszBuff
= 0;
703 DPRINT("Enter NtUserSetKeyboardState\n");
704 UserEnterShared();//faxme: this syscall doesnt seem to need any locking...
707 if( !NT_SUCCESS(MmCopyFromCaller(KeyStateBuf
,
709 sizeof(KeyStateBuf
))) )
711 DPRINT1( "Couldn't copy key state from caller.\n" );
714 OutPwszBuff
= ExAllocatePoolWithTag(NonPagedPool
,sizeof(WCHAR
) * cchBuff
, TAG_STRING
);
717 DPRINT1( "ExAllocatePool(%d) failed\n", sizeof(WCHAR
) * cchBuff
);
720 RtlZeroMemory( OutPwszBuff
, sizeof( WCHAR
) * cchBuff
);
722 ret
= ToUnicodeInner( wVirtKey
,
728 PsGetCurrentThreadWin32Thread() ?
729 PsGetCurrentThreadWin32Thread()->KeyboardLayout
->KBTables
: 0 );
731 MmCopyToCaller(pwszBuff
,OutPwszBuff
,sizeof(WCHAR
)*cchBuff
);
732 ExFreePool(OutPwszBuff
);
737 DPRINT("Leave NtUserSetKeyboardState, ret=%i\n",_ret_
);
742 static int W32kSimpleToupper( int ch
)
744 if( ch
>= 'a' && ch
<= 'z' )
751 NtUserGetKeyNameText( LONG lParam
, LPWSTR lpString
, int nSize
)
757 UINT ScanCode
= (lParam
>> 16) & 0xff;
758 BOOL ExtKey
= lParam
& (1<<24) ? TRUE
: FALSE
;
759 PKBDTABLES keyLayout
;
760 VSC_LPWSTR
*KeyNames
;
761 DECLARE_RETURN(DWORD
);
763 DPRINT("Enter NtUserGetKeyNameText\n");
766 keyLayout
= PsGetCurrentThreadWin32Thread() ?
767 PsGetCurrentThreadWin32Thread()->KeyboardLayout
->KBTables
: 0;
769 if( !keyLayout
|| nSize
< 1 )
772 if( lParam
& (1<<25) )
774 CareVk
= VkCode
= ScanToVk( ScanCode
, ExtKey
, keyLayout
);
775 if( VkCode
== VK_LSHIFT
|| VkCode
== VK_RSHIFT
)
777 if( VkCode
== VK_LCONTROL
|| VkCode
== VK_RCONTROL
)
778 VkCode
= VK_LCONTROL
;
779 if( VkCode
== VK_LMENU
|| VkCode
== VK_RMENU
)
784 VkCode
= ScanToVk( ScanCode
, ExtKey
, keyLayout
);
789 if( CareVk
!= VkCode
)
790 ScanCode
= VkToScan( VkCode
, ExtKey
, keyLayout
);
793 KeyNames
= keyLayout
->pKeyNamesExt
;
795 KeyNames
= keyLayout
->pKeyNames
;
797 for( i
= 0; KeyNames
[i
].pwsz
; i
++ )
799 if( KeyNames
[i
].vsc
== ScanCode
)
801 UINT StrLen
= wcslen(KeyNames
[i
].pwsz
);
802 UINT StrMax
= StrLen
> (nSize
- 1) ? (nSize
- 1) : StrLen
;
804 if( NT_SUCCESS( MmCopyToCaller( lpString
,
806 StrMax
* sizeof(WCHAR
) ) ) &&
807 NT_SUCCESS( MmCopyToCaller( lpString
+ StrMax
,
809 sizeof( WCHAR
) ) ) )
821 UCName
[0] = W32kSimpleToupper(IntMapVirtualKeyEx( VkCode
, 2, keyLayout
));
825 if( !NT_SUCCESS(MmCopyToCaller( lpString
, UCName
, 2 * sizeof(WCHAR
) )) )
832 DPRINT("Leave NtUserGetKeyNameText, ret=%i\n",_ret_
);
838 * Filter this message according to the current key layout, setting wParam
843 W32kKeyProcessMessage(LPMSG Msg
,
844 PKBDTABLES KeyboardLayout
,
847 DWORD ScanCode
= 0, ModifierBits
= 0;
849 DWORD BaseMapping
= 0;
851 static WORD NumpadConversion
[][2] =
852 { { VK_DELETE
, VK_DECIMAL
},
853 { VK_INSERT
, VK_NUMPAD0
},
854 { VK_END
, VK_NUMPAD1
},
855 { VK_DOWN
, VK_NUMPAD2
},
856 { VK_NEXT
, VK_NUMPAD3
},
857 { VK_LEFT
, VK_NUMPAD4
},
858 { VK_CLEAR
, VK_NUMPAD5
},
859 { VK_RIGHT
, VK_NUMPAD6
},
860 { VK_HOME
, VK_NUMPAD7
},
861 { VK_UP
, VK_NUMPAD8
},
862 { VK_PRIOR
, VK_NUMPAD9
},
864 PVSC_VK VscVkTable
= NULL
;
866 if( !KeyboardLayout
|| !Msg
||
867 (Msg
->message
!= WM_KEYDOWN
&& Msg
->message
!= WM_SYSKEYDOWN
&&
868 Msg
->message
!= WM_KEYUP
&& Msg
->message
!= WM_SYSKEYUP
) )
873 /* arty -- handle numpad -- On real windows, the actual key produced
874 * by the messaging layer is different based on the state of numlock. */
875 ModifierBits
= ModBits(KeyboardLayout
,gQueueKeyStateTable
);
877 /* Get the raw scan code, so we can look up whether the key is a numpad
880 * Shift and the LP_EXT_BIT cancel. */
881 ScanCode
= (Msg
->lParam
>> 16) & 0xff;
882 BaseMapping
= Msg
->wParam
=
883 IntMapVirtualKeyEx( ScanCode
, 1, KeyboardLayout
);
886 if( ScanCode
>= KeyboardLayout
->bMaxVSCtoVK
)
889 RawVk
= KeyboardLayout
->pusVSCtoVK
[ScanCode
];
895 /* ignore shift codes */
896 if( ScanCode
== 0x2A || ScanCode
== 0x36 )
900 VscVkTable
= KeyboardLayout
->pVSCtoVK_E0
;
902 else if( Prefix
== 0xE1 )
904 VscVkTable
= KeyboardLayout
->pVSCtoVK_E1
;
908 while (VscVkTable
->Vsc
)
910 if( VscVkTable
->Vsc
== ScanCode
)
912 RawVk
= VscVkTable
->Vk
;
918 if ((ModifierBits
& NUMLOCK_BIT
) &&
919 !(ModifierBits
& GetShiftBit(KeyboardLayout
, VK_SHIFT
)) &&
921 !(Msg
->lParam
& LP_EXT_BIT
))
923 /* The key in question is a numpad key. Search for a translation. */
924 for (i
= 0; NumpadConversion
[i
][0]; i
++)
926 if ((BaseMapping
& 0xff) == NumpadConversion
[i
][0]) /* RawVk? */
928 Msg
->wParam
= NumpadConversion
[i
][1];
934 DPRINT("Key: [%04x -> %04x]\n", BaseMapping
, Msg
->wParam
);
936 /* Now that we have the VK, we can set the keymap appropriately
937 * This is a better place for this code, as it's guaranteed to be
938 * run, unlike translate message. */
939 if (Msg
->message
== WM_KEYDOWN
|| Msg
->message
== WM_SYSKEYDOWN
)
941 SetKeyState( ScanCode
, Msg
->wParam
, Msg
->lParam
& LP_EXT_BIT
,
942 TRUE
); /* Strike key */
944 else if (Msg
->message
== WM_KEYUP
|| Msg
->message
== WM_SYSKEYUP
)
946 SetKeyState( ScanCode
, Msg
->wParam
, Msg
->lParam
& LP_EXT_BIT
,
947 FALSE
); /* Release key */
950 /* We need to unset SYSKEYDOWN if the ALT key is an ALT+Gr */
951 if( gQueueKeyStateTable
[VK_RMENU
] & KS_DOWN_BIT
)
953 if( Msg
->message
== WM_SYSKEYDOWN
)
954 Msg
->message
= WM_KEYDOWN
;
956 Msg
->message
= WM_KEYUP
;
969 case 0: /* Keyboard type */
970 return 4; /* AT-101 */
971 case 1: /* Keyboard Subtype */
972 return 0; /* There are no defined subtypes */
973 case 2: /* Number of F-keys */
974 return 12; /* We're doing an 101 for now, so return 12 F-keys */
976 DPRINT1("Unknown type!\n");
977 return 0; /* The book says 0 here, so 0 */
983 Based on TryToTranslateChar, instead of processing VirtualKey match,
984 look for wChar match.
993 /* FIXME: currently, this routine doesnt seem to need any locking */
994 PKBDTABLES KeyLayout
;
995 PVK_TO_WCHAR_TABLE vtwTbl
;
996 PVK_TO_WCHARS10 vkPtr
;
997 size_t size_this_entry
;
999 DWORD CapsMod
= 0, CapsState
= 0;
1001 DPRINT("NtUserVkKeyScanEx() wChar %d, KbdLayout 0x%p\n", wChar
, KeyboardLayout
);
1005 KeyLayout
= UserHklToKbl(KeyboardLayout
)->KBTables
;
1007 for (nMod
= 0; KeyLayout
->pVkToWcharTable
[nMod
].nModifications
; nMod
++)
1009 vtwTbl
= &KeyLayout
->pVkToWcharTable
[nMod
];
1010 size_this_entry
= vtwTbl
->cbSize
;
1011 vkPtr
= (PVK_TO_WCHARS10
)((BYTE
*)vtwTbl
->pVkToWchars
);
1013 while(vkPtr
->VirtualKey
)
1019 Should have only 8 valid possibilities. Including zero.
1021 for(CapsState
= 0; CapsState
< vtwTbl
->nModifications
; CapsState
++)
1023 if(vkPtr
->wch
[CapsState
] == wChar
)
1025 CapsMod
= KeyLayout
->pCharModifiers
->ModNumber
[CapsState
];
1026 DPRINT("nMod %d wC %04x: CapsMod %08x CapsState %08x MaxModBits %08x\n",
1027 nMod
, wChar
, CapsMod
, CapsState
, KeyLayout
->pCharModifiers
->wMaxModBits
);
1028 return ((CapsMod
<< 8)|(vkPtr
->VirtualKey
& 0xff));
1031 vkPtr
= (PVK_TO_WCHARS10
)(((BYTE
*)vkPtr
) + size_this_entry
);