ANSI Characters

Windows and Windows applications call the ToAsciiEx function to translate virtual-key codes to ANSI characters. The keyboard driver translate these key codes by checking the state of the virtual-shift keys (such as the VK_SHIFT, VK_CONTROL, and VK_MENU) and mapping the virtual-key code and shift state to the appropriate character. For example, on most U.S. keyboards if the VK_SHIFT key is up, the VK_2 virtual key code maps to the number 2 (ANSI 50); if VK_SHIFT is down, VK_2 maps to the at sign (@) (ANSI 64). For foreign-language keyboards, the keyboard also checks for a previously typed dead key before translating the virtual-key code.

Windows passes the address of the key-state array to the ToAsciiEx function, giving the keyboard driver access to the current state of all virtual keys including the shift keys. The key-state array also contains the shift state of the mouse buttons (that is, the corresponding virtual-key codes VK_LBUTTON, VK_RBUTTON, VK_CANCEL, and VK_MBUTTON).

The keyboard driver must provide keyboard layouts to map virtual keys to ANSI characters. Since the meaning of a virtual key depends on the state of the shift keys, the driver should provide layouts for each possible shift-key combination (for example, no shift key, VK_SHIFT, VK_CONTROL, and VK_MENU and VK_CONTROL combined). Windows does not require that all virtual keys map to ANSI characters for all shift-key combinations. Therefore, not all keyboard layouts need to map the complete virtual-key set.

See also ToAsciiEx