int ToAscii(uVirtKey, uScanCode, lpbKeyState, lpdwTransKey, fuState) | |||||
UINT uVirtKey; | /* virtual-key code, */ | ||||
UINT uScanCode; | /* scan code, */ | ||||
BYTE FAR* lpbKeyState; | /* address of key-state array | */ | |||
DWORD FAR* lpdwTransKey; | /* 32-bit buffer for translated key | */ | |||
UINT fuState; | /* active-menu flag, */ |
The ToAscii function translates the specified virtual-key code and keyboard state to the corresponding Windows character or characters.
uVirtKey
Specifies the virtual-key code to be translated.
uScanCode
Specifies the hardware scan code of the key to be translated. The high-order bit of this value is set if the key is not pressed (is up).
lpbKeyState
Points to a 256-byte array that contains the current keyboard state. Each element (byte) in the array contains the state of one key. If the high-order bit of a byte is set, the key is pressed (is down).
lpdwTransKey
Points to a doubleword buffer to receive the translated Windows character or characters.
fuState
Specifies whether a menu is active. This parameter must be 1 if a menu is active, or zero otherwise.
The return value is a negative value if the specified key is a dead key. Otherwise, it is one of the following values:
Value | Meaning |
2 | Two characters were copied to the buffer. This is usually an accent and a dead-key character, when the dead key cannot be translated otherwise. |
1 | One Windows character was copied to the buffer. |
0 | The specified virtual key has no translation for the current state of the keyboard. |
If a previous dead key is stored in the keyboard driver, the parameters supplied to the ToAscii function might not be sufficient to translate the virtual-key code.
Typically, ToAscii performs the translation based on the virtual-key code. In some cases, however, the uScanCode parameter may be used to distinguish between a key press and a key release. The scan code is used for translating ALT+number key combinations.