SetCapsLockState / SetNumLockState / SetScrollLockState

Sets the state of CapsLock/NumLock/ScrollLock. Can also force the key to stay on or off.

SetCapsLockState State
SetNumLockState State
SetScrollLockState State

Parameters

State

Type: String or Integer

If blank or omitted, the AlwaysOn/Off attribute of the key is removed (if present). Otherwise, specify one of the following values:

On or 1 (true): Turns on the key and removes the AlwaysOn/Off attribute of the key (if present).

Off or 0 (false): Turns off the key and removes the AlwaysOn/Off attribute of the key (if present).

AlwaysOn: Forces the key to stay on permanently.

AlwaysOff: Forces the key to stay off permanently.

Remarks

Alternatively to example #3 below, a key can also be toggled to its opposite state via the Send function, e.g. Send "{CapsLock}". However, sending {CapsLock} might require SetStoreCapsLockMode False beforehand.

Keeping a key AlwaysOn or AlwaysOff requires the keyboard hook, which will be automatically installed in such cases.

SetStoreCapsLockMode, GetKeyState

Examples

Turns on NumLock and removes the AlwaysOn/Off attribute of the key (if present).

SetNumLockState True

Forces ScrollLock to stay off permanently.

SetScrollLockState "AlwaysOff"

Toggles CapsLock to its opposite state.

SetCapsLockState !GetKeyState("CapsLock", "T")