Monday 28 November 2011

What are virtual key codes? in C programming

What are virtual key codes?

When your program receives a WM_KEYUP, WM_KEYDOWN, WM_SYSKEYUP, or WM_SYSKEYDOWN message, the wParam parameter will contain the keystroke’s virtual key code. This virtual key code can be used to reference what key on the keyboard was pressed. The key code does not map to any physical character set (such as the OEM key codes—see FAQ XXI.16), but rather it originates from a “virtual” table (set forth in windows.h) of key codes. Table XXI.17 lists some available virtual key codes.



















Many more virtual keys are available, but most of them depend on which international settings you have set up for your Windows configuration.

Note that besides being able to obtain the keystroke from Windows, you can also obtain the state of the Shift, Ctrl (Control), and Alt keys. You can do so by using the function GetKeyState(). For instance, the function
call
GetKeyState(VK_SHIFT);

returns a negative value if the Shift key is down (pressed). If the Shift key is not pressed, the return value is
positive.

Cross Reference:

XXI.15: What are OEM key codes?
XXI.16: Should a Windows program care about the OEM key codes?
XXI.18: What is a dead key?

No comments:

Post a Comment