Retrieves the virtual key code of a key.

VK := GetKeyVK(KeyName)



Type: String

This can be just about any single character from the keyboard or one of the key names from the key list, such as a mouse/joystick button. Examples: B, 5, LWin, RControl, Alt, Enter, Escape, LButton, MButton, Joy1.

Alternatively, an explicit virtual key code such as vkFF or an explicit scan code such as sc01D may be specified. This is useful in the rare case where a key has no name. The code of such a key can be determined by following the steps at the bottom of the key list page. Note that these codes must be in hexadecimal.

Known limitation: This function cannot differentiate between two keys which share the same virtual key code, such as Left and NumpadLeft.

Return Value

Type: Integer

This function returns the virtual key code of the specified key.


If you want to use the virtual key code later somewhere else in the script, it must first be converted to hexadecimal format, such as Format("vk{:X}", vk_code).


GetKeySC, GetKeyName, GetKeyState, Key List, Format



vk_code := GetKeyVK("Esc")
MsgBox Format("vk{:X}", vk_code) ; Shows vk1B