Keyboard Layout Functions

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 }

GetKeyboardLayout

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.

GetKeyInfo

Info := GetKeyInfo(KeyName , Layout)

Parameters

KeyName

Type: String

A key name from the key list, or a single character.

Layout

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.

Return Value

Type: Object or Integer

Returns 0 if KeyName cannot be resolved. Otherwise returns an object with the following properties:

PropertyTypeValue
VKIntegerThe virtual key code.
SCIntegerThe scan code.
NameStringThe canonical key name.
ModifiersIntegerThe modifiers needed to produce the key, as a bit mask.
PrefixStringThose modifiers as hotkey prefix symbols, for example +^.

Examples

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

List of Keys, GetKeyName, GetKeyVK, GetKeySC, GetKeyState