Identify the active keyboard layout and resolve a key name to the codes behind it.
These functions are exported by the KS module:
#Import "Ks" { GetKeyboardLayout, GetKeyInfo }
Layout := GetKeyboardLayout()
Returns Keysharp's identifier for the current keyboard layout, as a readable platform-native string. Returns "unknown" if the platform reports no layout.
Note: The string is platform-specific. Treat it as an opaque value to compare or to pass to GetKeyInfo, not as a value to parse.
Info := GetKeyInfo(KeyName , Layout)
Type: String
A key name from the key list, or a single character.
Type: String
If omitted, the current layout is used. Otherwise, specify a layout string obtained from GetKeyboardLayout to resolve the key as that layout would.
Returns 0 if KeyName cannot be resolved. Otherwise returns an object with the following properties:
| Property | Type | Value |
|---|---|---|
VK | Integer | The virtual key code. |
SC | Integer | The scan code. |
Name | String | The canonical key name. |
Modifiers | Integer | The modifiers needed to produce the key, as a bit mask. |
Prefix | String | Those modifiers as hotkey prefix symbols, for example +^. |
Reports the codes behind a character.
#Import "Ks" { GetKeyInfo }
Info := GetKeyInfo("!")
if Info
MsgBox "VK " Info.VK ", SC " Info.SC ", typed as " Info.Prefix Info.Name
Tests whether a key name is valid, since an unresolved name returns 0.
#Import "Ks" { GetKeyInfo }
for Name in ["Esc", "NotAKey"]
MsgBox Name ": " (GetKeyInfo(Name) ? "resolved" : "unknown")