Click to Rate and Give Feedback
MSDN
MSDN Library
User Interface
User Input
Keyboard Input
Functions
 VkKeyScan Function
VkKeyScan Function

The VkKeyScan function translates a character to the corresponding virtual-key code and shift state for the current keyboard.

This function has been superseded by the VkKeyScanEx function. You can still use VkKeyScan, however, if you do not need to specify a keyboard layout.

Syntax

SHORT VkKeyScan(      
    TCHAR ch );

Parameters

ch
[in] Specifies the character to be translated into a virtual-key code.

Return Value

If the function succeeds, the low-order byte of the return value contains the virtual-key code and the high-order byte contains the shift state, which can be a combination of the following flag bits.

If the function finds no key that translates to the passed character code, both the low-order and high-order bytes contain –1.

BitMeaning
1Either SHIFT key is pressed.
2Either CTRL key is pressed.
4Either ALT key is pressed.
8The Hankaku key is pressed
16Reserved (defined by the keyboard layout driver).
32Reserved (defined by the keyboard layout driver).

Remarks

For keyboard layouts that use the right-hand ALT key as a shift key (for example, the French keyboard layout), the shift state is represented by the value 6, because the right-hand ALT key is converted internally into CTRL+ALT.

Translations for the numeric keypad (VK_NUMPAD0 through VK_DIVIDE) are ignored. This function is intended to translate characters into keystrokes from the main keyboard section only. For example, the character "7" is translated into VK_7, not VK_NUMPAD7.

VkKeyScan is used by applications that send characters by using the WM_KEYUP and WM_KEYDOWN messages.

Windows 95/98/Me: VkKeyScanW is supported by the Microsoft Layer for Unicode (MSLU). To use this, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems.

Function Information

Minimum DLL Versionuser32.dll
HeaderDeclared in Winuser.h, include Windows.h
Import libraryUser32.lib
Minimum operating systems Windows 95, Windows NT 3.1
UnicodeImplemented as ANSI and Unicode versions.

See Also

Keyboard Input, GetAsyncKeyState, GetKeyboardState, GetKeyNameText, GetKeyState, SetKeyboardState, VkKeyScanEx, WM_KEYDOWN, WM_KEYUP
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker