ToAscii

Version 3.0

Syntax

int ToAscii(wVirtKey,wScanCode,lpKeyState,lpChar,wFlags)

This function translates the virtual-key code specified by the wVirtKey parameter and the current keyboard state specified by the lpKeyState parameter to the corresponding ANSI character or characters.

Parameter Type/Description  

wVirtKey WORD Specifies the virtual-key code to be translated.  
wScanCode WORD Specifies the “hardware” raw scan code of the key to be translated. The high-order bit of this value is set if the key is up.  
lpKeyState LPSTR Points to an array of 256 bytes, each of which contains the state of one key. If the high-order bit of the byte is set the key is down.  
lpChar LPVOID Points to a 32-bit buffer which receives the translated ANSI character or characters.  
wFlags WORD The bit 0 flag's menu display.  

Return Value

The return value specifies the number of characters copied to the buffer identified by the lpChar parameter. The return value is negative if the key was 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 ANSI character was copied to the buffer.
0 The specified virtual key has no translation for the current state of the keyboard.

Comments

The parameters supplied to the ToAscii function might not be sufficient to translate the virtual-key code because a previous dead key is stored in the keyboard driver.

Typically, ToAscii performs the translation based on the virtual-key code. In some cases, however, the wScanCode parameter may be used to distinguish between a key depression or a key release. The scan code is used for translating ALT+NUMBER key combinations.