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_LCONTROL
, VK_RCONTROL
) &
201 ModBits
|= GetShiftBit( pkKT
, VK_CONTROL
);
203 if (KeysSet( pkKT
, KeyState
, VK_LMENU
, VK_RMENU
) &
205 ModBits
|= GetShiftBit( pkKT
, VK_MENU
);
208 if (KeysSet( pkKT
, KeyState
, VK_RMENU
, 0 ) &
210 ModBits
|= GetShiftBit( pkKT
, VK_CONTROL
);
212 /* Deal with VK_CAPITAL */
213 if (KeysSet( pkKT
, KeyState
, VK_CAPITAL
, 0 ) & KS_LOCK_BIT
)
215 ModBits
|= CAPITAL_BIT
;
218 /* Deal with VK_NUMLOCK */
219 if (KeysSet( pkKT
, KeyState
, VK_NUMLOCK
, 0 ) & KS_LOCK_BIT
)
221 ModBits
|= NUMLOCK_BIT
;
224 DPRINT( "Current Mod Bits: %x\n", ModBits
);
229 static BOOL
TryToTranslateChar(WORD wVirtKey
,
233 PWCHAR pwcTranslatedChar
,
234 PKBDTABLES keyLayout
)
236 PVK_TO_WCHAR_TABLE vtwTbl
;
237 PVK_TO_WCHARS10 vkPtr
;
238 size_t size_this_entry
;
240 DWORD CapsMod
= 0, CapsState
= 0;
242 CapsState
= ModBits
& ~MOD_BITS_MASK
;
243 ModBits
= ModBits
& MOD_BITS_MASK
;
245 DPRINT ( "TryToTranslate: %04x %x\n", wVirtKey
, ModBits
);
247 if (ModBits
> keyLayout
->pCharModifiers
->wMaxModBits
)
251 for (nMod
= 0; keyLayout
->pVkToWcharTable
[nMod
].nModifications
; nMod
++)
253 vtwTbl
= &keyLayout
->pVkToWcharTable
[nMod
];
254 size_this_entry
= vtwTbl
->cbSize
;
255 vkPtr
= (PVK_TO_WCHARS10
)((BYTE
*)vtwTbl
->pVkToWchars
);
256 while(vkPtr
->VirtualKey
)
258 if( wVirtKey
== (vkPtr
->VirtualKey
& 0xff) )
260 CapsMod
= keyLayout
->pCharModifiers
->ModNumber
262 ((CapsState
& CAPITAL_BIT
) ? vkPtr
->Attributes
: 0)];
264 if( CapsMod
>= keyLayout
->pVkToWcharTable
[nMod
].nModifications
)
268 keyLayout
->pVkToWcharTable
[nMod
].nModifications
)
271 CapsMod
&= MaxBit
- 1; /* Guarantee that CapsMod lies
275 *pbDead
= vkPtr
->wch
[CapsMod
] == WCH_DEAD
;
276 *pbLigature
= vkPtr
->wch
[CapsMod
] == WCH_LGTR
;
277 *pwcTranslatedChar
= vkPtr
->wch
[CapsMod
];
279 DPRINT("%d %04x: CapsMod %08x CapsState %08x Char %04x\n",
281 CapsMod
, CapsState
, *pwcTranslatedChar
);
285 vkPtr
= (PVK_TO_WCHARS10
)(((BYTE
*)vkPtr
) + size_this_entry
);
286 if( vkPtr
->VirtualKey
!= 0xff )
288 DPRINT( "Found dead key with no trailer in the table.\n" );
289 DPRINT( "VK: %04x, ADDR: %08x\n", wVirtKey
, (int)vkPtr
);
292 *pwcTranslatedChar
= vkPtr
->wch
[CapsMod
];
296 vkPtr
= (PVK_TO_WCHARS10
)(((BYTE
*)vkPtr
) + size_this_entry
);
304 ToUnicodeInner(UINT wVirtKey
,
312 WCHAR wcTranslatedChar
;
319 if( TryToTranslateChar( wVirtKey
,
320 ModBits( pkKT
, lpKeyState
),
328 DPRINT("Not handling ligature (yet)\n" );
333 pwszBuff
[0] = wcTranslatedChar
;
335 return bDead
? -1 : 1;
342 DWORD FASTCALL
UserGetKeyState(DWORD key
)
348 ret
= ((DWORD
)(gQueueKeyStateTable
[key
] & KS_DOWN_BIT
) << 8 ) |
349 (gQueueKeyStateTable
[key
] & KS_LOCK_BIT
);
361 DECLARE_RETURN(DWORD
);
363 DPRINT("Enter NtUserGetKeyState\n");
364 UserEnterExclusive();
366 RETURN(UserGetKeyState(key
));
369 DPRINT("Leave NtUserGetKeyState, ret=%i\n",_ret_
);
376 DWORD FASTCALL
UserGetAsyncKeyState(DWORD key
)
382 ret
= ((DWORD
)(gQueueKeyStateTable
[key
] & KS_DOWN_BIT
) << 8 ) |
383 (gQueueKeyStateTable
[key
] & KS_LOCK_BIT
);
393 NtUserGetAsyncKeyState(
396 DECLARE_RETURN(DWORD
);
398 DPRINT("Enter NtUserGetAsyncKeyState\n");
399 UserEnterExclusive();
401 RETURN(UserGetAsyncKeyState(key
));
404 DPRINT("Leave NtUserGetAsyncKeyState, ret=%i\n",_ret_
);
411 int STDCALL
ToUnicodeEx( UINT wVirtKey
,
419 int ToUnicodeResult
= 0;
421 if (0 == (lpKeyState
[wVirtKey
] & KS_DOWN_BIT
))
427 ToUnicodeResult
= ToUnicodeInner( wVirtKey
,
433 PsGetCurrentThreadWin32Thread() ?
434 PsGetCurrentThreadWin32Thread()->KeyboardLayout
->KBTables
: 0 );
437 return ToUnicodeResult
;
440 int STDCALL
ToUnicode( UINT wVirtKey
,
447 return ToUnicodeEx( wVirtKey
,
458 IntTranslateKbdMessage(LPMSG lpMsg
,
461 static INT dead_char
= 0;
465 PKBDTABLES keyLayout
;
470 keyLayout
= PsGetCurrentThreadWin32Thread()->KeyboardLayout
->KBTables
;
474 if (lpMsg
->message
!= WM_KEYDOWN
&& lpMsg
->message
!= WM_SYSKEYDOWN
)
477 ScanCode
= (lpMsg
->lParam
>> 16) & 0xff;
479 /* All messages have to contain the cursor point. */
480 IntGetCursorLocation(PsGetCurrentThreadWin32Thread()->Desktop
->WindowStation
,
483 UState
= ToUnicodeInner(lpMsg
->wParam
, HIWORD(lpMsg
->lParam
) & 0xff,
484 gQueueKeyStateTable
, wp
, 2, 0,
489 NewMsg
.message
= (lpMsg
->message
== WM_KEYDOWN
) ? WM_CHAR
: WM_SYSCHAR
;
494 DPRINT("PREVIOUS DEAD CHAR: %c\n", dead_char
);
496 for( i
= 0; keyLayout
->pDeadKey
[i
].dwBoth
; i
++ )
498 first
= keyLayout
->pDeadKey
[i
].dwBoth
>> 16;
499 second
= keyLayout
->pDeadKey
[i
].dwBoth
;
500 if (first
== dead_char
&& second
== wp
[0])
502 wp
[0] = keyLayout
->pDeadKey
[i
].wchComposed
;
508 DPRINT("FINAL CHAR: %c\n", wp
[0]);
513 NewMsg
.hwnd
= lpMsg
->hwnd
;
514 NewMsg
.wParam
= dead_char
;
515 NewMsg
.lParam
= lpMsg
->lParam
;
517 MsqPostMessage(PsGetCurrentThreadWin32Thread()->MessageQueue
, &NewMsg
, FALSE
, QS_KEY
);
520 NewMsg
.hwnd
= lpMsg
->hwnd
;
521 NewMsg
.wParam
= wp
[0];
522 NewMsg
.lParam
= lpMsg
->lParam
;
523 DPRINT( "CHAR='%c' %04x %08x\n", wp
[0], wp
[0], lpMsg
->lParam
);
524 MsqPostMessage(PsGetCurrentThreadWin32Thread()->MessageQueue
, &NewMsg
, FALSE
, QS_KEY
);
527 else if (UState
== -1)
530 (lpMsg
->message
== WM_KEYDOWN
) ? WM_DEADCHAR
: WM_SYSDEADCHAR
;
531 NewMsg
.hwnd
= lpMsg
->hwnd
;
532 NewMsg
.wParam
= wp
[0];
533 NewMsg
.lParam
= lpMsg
->lParam
;
535 MsqPostMessage(PsGetCurrentThreadWin32Thread()->MessageQueue
, &NewMsg
, FALSE
, QS_KEY
);
544 NtUserGetKeyboardState(
548 DECLARE_RETURN(DWORD
);
550 DPRINT("Enter NtUserGetKeyboardState\n");
555 if(!NT_SUCCESS(MmCopyToCaller(lpKeyState
, gQueueKeyStateTable
, 256)))
562 DPRINT("Leave NtUserGetKeyboardState, ret=%i\n",_ret_
);
569 NtUserSetKeyboardState(LPBYTE lpKeyState
)
572 DECLARE_RETURN(DWORD
);
574 DPRINT("Enter NtUserSetKeyboardState\n");
575 UserEnterExclusive();
579 if(! NT_SUCCESS(MmCopyFromCaller(gQueueKeyStateTable
, lpKeyState
, 256)))
586 DPRINT("Leave NtUserSetKeyboardState, ret=%i\n",_ret_
);
591 static UINT
VkToScan( UINT Code
, BOOL ExtCode
, PKBDTABLES pkKT
)
595 for( i
= 0; i
< pkKT
->bMaxVSCtoVK
; i
++ )
597 if( pkKT
->pusVSCtoVK
[i
] == Code
)
606 UINT
ScanToVk( UINT Code
, BOOL ExtKey
, PKBDTABLES pkKT
)
610 DPRINT("ScanToVk: No layout\n");
618 for( i
= 0; pkKT
->pVSCtoVK_E0
[i
].Vsc
; i
++ )
620 if( pkKT
->pVSCtoVK_E0
[i
].Vsc
== Code
)
621 return pkKT
->pVSCtoVK_E0
[i
].Vk
& 0xff;
623 for( i
= 0; pkKT
->pVSCtoVK_E1
[i
].Vsc
; i
++ )
625 if( pkKT
->pVSCtoVK_E1
[i
].Vsc
== Code
)
626 return pkKT
->pVSCtoVK_E1
[i
].Vk
& 0xff;
633 if( Code
>= pkKT
->bMaxVSCtoVK
)
637 return pkKT
->pusVSCtoVK
[Code
] & 0xff;
642 * Map a virtual key code, or virtual scan code, to a scan code, key code,
643 * or unshifted unicode character.
647 * 0 -- Code is a virtual key code that is converted into a virtual scan code
648 * that does not distinguish between left and right shift keys.
649 * 1 -- Code is a virtual scan code that is converted into a virtual key code
650 * that does not distinguish between left and right shift keys.
651 * 2 -- Code is a virtual key code that is converted into an unshifted unicode
653 * 3 -- Code is a virtual scan code that is converted into a virtual key code
654 * that distinguishes left and right shift keys.
655 * KeyLayout: Keyboard layout handle (currently, unused)
660 static UINT
IntMapVirtualKeyEx( UINT Code
, UINT Type
, PKBDTABLES keyLayout
)
667 if( Code
== VK_RSHIFT
)
669 if( Code
== VK_RMENU
)
671 if( Code
== VK_RCONTROL
)
673 ret
= VkToScan( Code
, FALSE
, keyLayout
);
678 DontDistinguishShifts
679 (IntMapVirtualKeyEx( Code
, 3, keyLayout
) );
686 ret
= VkToScan( Code
, FALSE
, keyLayout
);
687 ToUnicodeInner( Code
, ret
, 0, wp
, 2, 0, keyLayout
);
694 ret
= ScanToVk( Code
, FALSE
, keyLayout
);
703 NtUserMapVirtualKeyEx( UINT Code
, UINT Type
, DWORD keyboardId
, HKL dwhkl
)
705 PKBDTABLES keyLayout
;
706 DECLARE_RETURN(UINT
);
708 DPRINT("Enter NtUserMapVirtualKeyEx\n");
709 UserEnterExclusive();
711 keyLayout
= PsGetCurrentThreadWin32Thread() ? PsGetCurrentThreadWin32Thread()->KeyboardLayout
->KBTables
: 0;
716 RETURN(IntMapVirtualKeyEx( Code
, Type
, keyLayout
));
719 DPRINT("Leave NtUserMapVirtualKeyEx, ret=%i\n",_ret_
);
736 BYTE KeyStateBuf
[0x100];
737 PWCHAR OutPwszBuff
= 0;
741 DPRINT("Enter NtUserSetKeyboardState\n");
742 UserEnterShared();//faxme: this syscall doesnt seem to need any locking...
745 if( !NT_SUCCESS(MmCopyFromCaller(KeyStateBuf
,
747 sizeof(KeyStateBuf
))) )
749 DPRINT1( "Couldn't copy key state from caller.\n" );
752 OutPwszBuff
= ExAllocatePoolWithTag(NonPagedPool
,sizeof(WCHAR
) * cchBuff
, TAG_STRING
);
755 DPRINT1( "ExAllocatePool(%d) failed\n", sizeof(WCHAR
) * cchBuff
);
758 RtlZeroMemory( OutPwszBuff
, sizeof( WCHAR
) * cchBuff
);
760 ret
= ToUnicodeEx( wVirtKey
,
768 MmCopyToCaller(pwszBuff
,OutPwszBuff
,sizeof(WCHAR
)*cchBuff
);
769 ExFreePool(OutPwszBuff
);
774 DPRINT("Leave NtUserSetKeyboardState, ret=%i\n",_ret_
);
779 static int W32kSimpleToupper( int ch
)
781 if( ch
>= 'a' && ch
<= 'z' )
788 NtUserGetKeyNameText( LONG lParam
, LPWSTR lpString
, int nSize
)
794 UINT ScanCode
= (lParam
>> 16) & 0xff;
795 BOOL ExtKey
= lParam
& (1<<24) ? TRUE
: FALSE
;
796 PKBDTABLES keyLayout
;
797 VSC_LPWSTR
*KeyNames
;
798 DECLARE_RETURN(DWORD
);
800 DPRINT("Enter NtUserGetKeyNameText\n");
803 keyLayout
= PsGetCurrentThreadWin32Thread() ?
804 PsGetCurrentThreadWin32Thread()->KeyboardLayout
->KBTables
: 0;
806 if( !keyLayout
|| nSize
< 1 )
809 if( lParam
& (1<<25) )
811 CareVk
= VkCode
= ScanToVk( ScanCode
, ExtKey
, keyLayout
);
812 if( VkCode
== VK_LSHIFT
|| VkCode
== VK_RSHIFT
)
814 if( VkCode
== VK_LCONTROL
|| VkCode
== VK_RCONTROL
)
815 VkCode
= VK_LCONTROL
;
816 if( VkCode
== VK_LMENU
|| VkCode
== VK_RMENU
)
821 VkCode
= ScanToVk( ScanCode
, ExtKey
, keyLayout
);
826 if( CareVk
!= VkCode
)
827 ScanCode
= VkToScan( VkCode
, ExtKey
, keyLayout
);
830 KeyNames
= keyLayout
->pKeyNamesExt
;
832 KeyNames
= keyLayout
->pKeyNames
;
834 for( i
= 0; KeyNames
[i
].pwsz
; i
++ )
836 if( KeyNames
[i
].vsc
== ScanCode
)
838 UINT StrLen
= wcslen(KeyNames
[i
].pwsz
);
839 UINT StrMax
= StrLen
> (nSize
- 1) ? (nSize
- 1) : StrLen
;
841 if( NT_SUCCESS( MmCopyToCaller( lpString
,
843 StrMax
* sizeof(WCHAR
) ) ) &&
844 NT_SUCCESS( MmCopyToCaller( lpString
+ StrMax
,
846 sizeof( WCHAR
) ) ) )
858 UCName
[0] = W32kSimpleToupper(IntMapVirtualKeyEx( VkCode
, 2, keyLayout
));
862 if( !NT_SUCCESS(MmCopyToCaller( lpString
, UCName
, 2 * sizeof(WCHAR
) )) )
869 DPRINT("Leave NtUserGetKeyNameText, ret=%i\n",_ret_
);
875 * Filter this message according to the current key layout, setting wParam
880 W32kKeyProcessMessage(LPMSG Msg
,
881 PKBDTABLES KeyboardLayout
,
884 DWORD ScanCode
= 0, ModifierBits
= 0;
886 DWORD BaseMapping
= 0;
888 static WORD NumpadConversion
[][2] =
889 { { VK_DELETE
, VK_DECIMAL
},
890 { VK_INSERT
, VK_NUMPAD0
},
891 { VK_END
, VK_NUMPAD1
},
892 { VK_DOWN
, VK_NUMPAD2
},
893 { VK_NEXT
, VK_NUMPAD3
},
894 { VK_LEFT
, VK_NUMPAD4
},
895 { VK_CLEAR
, VK_NUMPAD5
},
896 { VK_RIGHT
, VK_NUMPAD6
},
897 { VK_HOME
, VK_NUMPAD7
},
898 { VK_UP
, VK_NUMPAD8
},
899 { VK_PRIOR
, VK_NUMPAD9
},
901 PVSC_VK VscVkTable
= NULL
;
903 if( !KeyboardLayout
|| !Msg
||
904 (Msg
->message
!= WM_KEYDOWN
&& Msg
->message
!= WM_SYSKEYDOWN
&&
905 Msg
->message
!= WM_KEYUP
&& Msg
->message
!= WM_SYSKEYUP
) )
910 /* arty -- handle numpad -- On real windows, the actual key produced
911 * by the messaging layer is different based on the state of numlock. */
912 ModifierBits
= ModBits(KeyboardLayout
,gQueueKeyStateTable
);
914 /* Get the raw scan code, so we can look up whether the key is a numpad
917 * Shift and the LP_EXT_BIT cancel. */
918 ScanCode
= (Msg
->lParam
>> 16) & 0xff;
919 BaseMapping
= Msg
->wParam
=
920 IntMapVirtualKeyEx( ScanCode
, 1, KeyboardLayout
);
923 if( ScanCode
>= KeyboardLayout
->bMaxVSCtoVK
)
926 RawVk
= KeyboardLayout
->pusVSCtoVK
[ScanCode
];
932 /* ignore shift codes */
933 if( ScanCode
== 0x2A || ScanCode
== 0x36 )
937 VscVkTable
= KeyboardLayout
->pVSCtoVK_E0
;
939 else if( Prefix
== 0xE1 )
941 VscVkTable
= KeyboardLayout
->pVSCtoVK_E1
;
945 while (VscVkTable
->Vsc
)
947 if( VscVkTable
->Vsc
== ScanCode
)
949 RawVk
= VscVkTable
->Vk
;
955 if ((ModifierBits
& NUMLOCK_BIT
) &&
956 !(ModifierBits
& GetShiftBit(KeyboardLayout
, VK_SHIFT
)) &&
958 !(Msg
->lParam
& LP_EXT_BIT
))
960 /* The key in question is a numpad key. Search for a translation. */
961 for (i
= 0; NumpadConversion
[i
][0]; i
++)
963 if ((BaseMapping
& 0xff) == NumpadConversion
[i
][0]) /* RawVk? */
965 Msg
->wParam
= NumpadConversion
[i
][1];
971 DPRINT("Key: [%04x -> %04x]\n", BaseMapping
, Msg
->wParam
);
973 /* Now that we have the VK, we can set the keymap appropriately
974 * This is a better place for this code, as it's guaranteed to be
975 * run, unlike translate message. */
976 if (Msg
->message
== WM_KEYDOWN
|| Msg
->message
== WM_SYSKEYDOWN
)
978 SetKeyState( ScanCode
, Msg
->wParam
, Msg
->lParam
& LP_EXT_BIT
,
979 TRUE
); /* Strike key */
981 else if (Msg
->message
== WM_KEYUP
|| Msg
->message
== WM_SYSKEYUP
)
983 SetKeyState( ScanCode
, Msg
->wParam
, Msg
->lParam
& LP_EXT_BIT
,
984 FALSE
); /* Release key */
987 /* We need to unset SYSKEYDOWN if the ALT key is an ALT+Gr */
988 if( gQueueKeyStateTable
[VK_RMENU
] & KS_DOWN_BIT
)
990 if( Msg
->message
== WM_SYSKEYDOWN
)
991 Msg
->message
= WM_KEYDOWN
;
993 Msg
->message
= WM_KEYUP
;
1001 UserGetKeyboardType(
1006 case 0: /* Keyboard type */
1007 return 4; /* AT-101 */
1008 case 1: /* Keyboard Subtype */
1009 return 0; /* There are no defined subtypes */
1010 case 2: /* Number of F-keys */
1011 return 12; /* We're doing an 101 for now, so return 12 F-keys */
1013 DPRINT1("Unknown type!\n");
1014 return 0; /* The book says 0 here, so 0 */
1020 Based on TryToTranslateChar, instead of processing VirtualKey match,
1021 look for wChar match.
1027 DWORD KeyboardLayout
,
1030 /* FAXME: currently, this routine doesnt seem to need any locking */
1032 PKBDTABLES KeyLayout
;
1033 PVK_TO_WCHAR_TABLE vtwTbl
;
1034 PVK_TO_WCHARS10 vkPtr
;
1035 size_t size_this_entry
;
1037 DWORD CapsMod
= 0, CapsState
= 0;
1041 KeyLayout
= (PKBDTABLES
) KeyboardLayout
;
1043 for (nMod
= 0; KeyLayout
->pVkToWcharTable
[nMod
].nModifications
; nMod
++)
1045 vtwTbl
= &KeyLayout
->pVkToWcharTable
[nMod
];
1046 size_this_entry
= vtwTbl
->cbSize
;
1047 vkPtr
= (PVK_TO_WCHARS10
)((BYTE
*)vtwTbl
->pVkToWchars
);
1049 while(vkPtr
->VirtualKey
)
1055 Should have only 8 valid possibilities. Including zero.
1057 for(CapsState
= 0; CapsState
< vtwTbl
->nModifications
; CapsState
++)
1059 if(vkPtr
->wch
[CapsState
] == wChar
)
1061 CapsMod
= KeyLayout
->pCharModifiers
->ModNumber
[CapsState
];
1062 DPRINT("nMod %d wC %04x: CapsMod %08x CapsState %08x MaxModBits %08x\n",
1063 nMod
, wChar
, CapsMod
, CapsState
, KeyLayout
->pCharModifiers
->wMaxModBits
);
1064 return ((CapsMod
<< 8)|(vkPtr
->VirtualKey
& 0xff));
1067 vkPtr
= (PVK_TO_WCHARS10
)(((BYTE
*)vkPtr
) + size_this_entry
);