The ToAsciiEx function translates the specified virtual-key code and keyboard state to the corresponding character or characters. The function translates the code using the input language and physical keyboard layout identified by the given keyboard layout handle.
int ToAsciiEx(
UINT uVirtKey, // virtual-key code
UINT uScanCode, // scan code
PBYTE lpKeyState, // key-state array
LPWORD lpChar, // buffer for translated key
UINT uFlags, // active-menu flag
HKL dwhkl // keyboard layout handle
);
The low bit, if set, indicates that the key is toggled on. In this function, only the toggle bit of the caps lock key is relevant. The toggle state of the num lock and scroll lock keys is ignored.
If the specified key is a dead key, the return value is negative. Otherwise, it is one of the following values.
Value | Meaning |
---|---|
0 | The specified virtual key has no translation for the current state of the keyboard. |
1 | One character was copied to the buffer. |
2 | Two characters were copied to the buffer. This usually happens when a dead-key character (accent or diacritic) stored in the keyboard layout cannot be composed with the specified virtual key to form a single character. |
The parameters supplied to the ToAsciiEx function might not be sufficient to translate the virtual-key code, because a previous dead key is stored in the keyboard layout.
Typically, ToAsciiEx performs the translation based on the virtual-key code. In some cases, however, bit 15 of 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.
Although num lock is a toggle key that affects keyboard behavior, ToAsciiEx ignores the toggle setting (the low bit) of lpKeyState (VK_NUMLOCK, because the uVirtKey parameter alone is sufficient to distinguish the cursor movement keys (VK_HOME, VK_INSERT, and so on) from the numeric keys (VK_DECIMAL, VK_NUMPAD0 - VK_NUMPAD9).
Windows NT: Requires version 4.0 or later.
Windows: Requires Windows 95 or later.
Windows CE: Unsupported.
Header: Declared in winuser.h.
Import Library: Use user32.lib.
Keyboard Input Overview, Keyboard Input Functions, LoadKeyboardLayout, MapVirtualKeyEx, OemKeyScan, ToAscii, VkKeyScan