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 an identifier for the current keyboard layout, or an empty string if the platform reports no layout. The string is platform-specific: treat it as an opaque value to compare or to pass to GetKeyInfo.
On Linux, the layout is queried through keysharp-desktop. On some Wayland sessions, the result may not reflect a recent layout switch.
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. On Linux and macOS, this parameter is ignored and the current layout is used.
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