Click to See Complete Forum and Search --> : Virtual Key Codes
Ruth Glushkin
December 7th, 1999, 08:43 AM
Could you, please, help me.
Is there any API function, which can give me different codes
for Left and Right Shift, Ctrl, Alt?
I know how to use GetAsyncKeyState and GetKeyboardState
but they give the same Virtual Codes for them.
Thank you in advance.
Lothar Haensler
December 7th, 1999, 09:55 AM
from the online docs:
"An application can use the virtual-key code constants VK_SHIFT, VK_CONTROL and VK_MENU as indices into the array pointed to by lpKeyState. This gives the status of the SHIFT, CTRL, or ALT keys without distinguishing between left and right. An application can also use the following virtual-key code constants as indices to distinguish between the left and right instances of those keys:
VK_LSHIFT
VK_RSHIFT
VK_LCONTROL
VK_RCONTROL
VK_LMENU
VK_RMENU
These left- and right-distinguishing constants are available to an application only through the GetKeyboardState, SetKeyboardState, GetAsyncKeyState, GetKeyState, and MapVirtualKey functions. "
Thus, check for VK_LSHIFT to find out if the left shift key has been pressed.
This is defined as 0xA0 which is different from VK_SHIFT (0x10)
larrymullins
December 8th, 1999, 07:52 AM
I am having the same problem. I tried the last message and did not work. Has anyone a sample they have tried that works in VB5/6.
Lothar Haensler
December 8th, 1999, 08:37 AM
option Explicit
private Declare Function GetAsyncKeyState Lib "user32" (byval vKey as Long) as Integer
Const VK_LSHIFT = &HA0
Const VK_SHIFT = &H10
private Sub Form_KeyUp(KeyCode as Integer, Shift as Integer)
Dim lResult as Integer
lResult = GetAsyncKeyState(VK_LSHIFT)
List1.AddItem "LShift " & lResult, 0
lResult = GetAsyncKeyState(VK_SHIFT)
List1.AddItem "Shift " & lResult, 0
End Sub
set Form - keypreview to true.
if GetAsyncKeyState(VK_LSHIFT) returns 1, then the LEFT shift key has been pressed.
It will not return 1 (but 0), if the right shift key has been pressed.
GetAsyncKeyState(VK_SHIFT) will always return 1 (if ANY one of the shift keys is pressed).
This does not work in Win95/98.
I have tested this in NT 4 with VB 6
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.