Quick question: GetAsyncKeyState

Started by
5 comments, last by Dave Hunt 17 years, 9 months ago
When using the VK_ type of GetAsyncKeyState, why is there a ID for VK_LSHIFT, VK_RSHIFT, and VK_SHIFT? What does VK_SHIFT do? Is it for reading whether either of them are down, or does it serve a different purpose? Same thing with VK_CONTROL.
Advertisement
Quote:From MSDN
You can use the virtual-key code constants VK_SHIFT, VK_CONTROL, and VK_MENU as values for the vKey parameter. This gives the state of the SHIFT, CTRL, or ALT keys without distinguishing between left and right.

Windows NT/2000/XP: You can use the following virtual-key code constants as values for vKey to distinguish between the left and right instances of those keys.

Code Meaning
VK_LSHIFT Left-shift key.
VK_RSHIFT Right-shift key.
VK_LCONTROL Left-control key.
VK_RCONTROL Right-control key.
VK_LMENU Left-menu key.
VK_RMENU Right-menu key.


These left- and right-distinguishing constants are only available when you call the GetKeyboardState, SetKeyboardState, GetAsyncKeyState, GetKeyState, and MapVirtualKey functions.


Quote:Original post by Servant of the Lord
What does VK_SHIFT do? Is it for reading whether either of them are down, or does it serve a different purpose? Same thing with VK_CONTROL.


Upon inspections of the virtual key code table on MSDN, it would appear the answer is yes. It says VK_LSHIFT = left shift key, VK_RSHIFT = right shift key and VK_SHIFT = shift key. The same pattern applies to the control keys. Hope that helps.

-AJ

EDIT: Blast! Beaten to it.
V/R,-AJThere are 10 kinds of people in the world: Those who understand binary and those who don't...
Thanks guys, I was looking through MSDN, but I have trouble navigating it.

Many thanks!

Oh, and another thing. 0-9 and A-Z doesn't have any VK_ names, as far as I can tell, so I have to use it's hexidecimal IDs?
Quote:Original post by Servant of the Lord
Thanks guys, I was looking through MSDN, but I have trouble navigating it.

Many thanks!

Oh, and another thing. 0-9 and A-Z doesn't have any VK_ names, as far as I can tell, so I have to use it's hexidecimal IDs?


As far as I know, yes. Or you can be evil, and copy this to your project:

const WORD VK_A = 0x41;const WORD VK_B = 0x42;const WORD VK_C = 0x43;const WORD VK_D = 0x44;const WORD VK_E = 0x45;const WORD VK_F = 0x46;const WORD VK_G = 0x47;const WORD VK_H = 0x48;const WORD VK_I = 0x49;const WORD VK_J = 0x4A;const WORD VK_K = 0x4B;const WORD VK_L = 0x4C;const WORD VK_M = 0x4D;const WORD VK_N = 0x4E;const WORD VK_O = 0x4F;const WORD VK_P = 0x50;const WORD VK_Q = 0x51;const WORD VK_R = 0x52;const WORD VK_S = 0x53;const WORD VK_T = 0x54;const WORD VK_U = 0x55;const WORD VK_V = 0x56;const WORD VK_W = 0x57;const WORD VK_X = 0x58;const WORD VK_Y = 0x59;const WORD VK_Z = 0x5A;//=====================const WORD VK_ALT = VK_MENU;const WORD VK_ENTER = VK_RETURN;const WORD VK_CTRL = VK_CONTROL;const WORD VK_BACKSPACE = VK_BACK;


(The last 4 are just my own personal preference.)
.:<<-v0d[KA]->>:.
Okay thanks.
For A-Z and 0-9, you can just use 'A', '0', etc. No need for a macro.

This topic is closed to new replies.

Advertisement