AROYN UI LIBRARY / UI COMPONENTS

Keybind

Capture a keyboard binding and handle Toggle, Hold or Always activation.

Create Keybind#

Capture a keyboard binding and handle Toggle, Hold or Always activation.

The constructor returns a Keybind handle. The snippet assumes section exists, as created in Quick start.

LUAU
local keybind = section:CreateKeybind({
    Name = "Details shortcut", Flag = "shortcut", Default = "H", Mode = "Toggle",
    Callback = function(key) print("Binding:", key and key.Name or "None") end,
    OnActivate = function(active, key, mode) print(active, key, mode) end,
})

Arguments#

OptionTypeDefaultMeaning
DefaultEnum.KeyCode | string?nilEnum value or key name; None means unbound.
Mode"Toggle" | "Hold" | "Always""Toggle"Shortcut activation behavior.
Callbackfunction(Enum.KeyCode?)nilBinding or notifying mode change; separate from activation.
OnActivatefunction(boolean, Enum.KeyCode?, string)nilReceives active state, current key and mode.

Also accepts common options: Name, Description, Disabled and Callback; stateful controls additionally support Flag, Persist and Sensitive.

Manage state#

LUAU
local _, valid = keybind:SetValue("J")
assert(valid)
keybind:SetMode("Hold")
print(keybind:GetValue(), keybind:GetMode(), keybind:GetActive())
local capturing = keybind:BeginCapture()
keybind:CancelCapture()

Returned methods#

MethodReturnsBehavior
GetValue()Enum.KeyCode?Current binding.
SetValue(key, notify?)self, valid:booleanInvalid setter leaves binding unchanged; default notify=false.
GetMode() / SetMode(mode, notify?)string / selfToggle, Hold or Always. A changed SetMode(mode, true) also calls Callback(currentKey) and allows activation notifications.
GetActive()booleanCurrent shortcut activation.
BeginCapture()booleanRequests key capture; false if unavailable.
CancelCapture()selfEnds capture.
IsCapturing()booleanReads capture state.
Close()selfCancels capture and active state.
SetDisabled(boolean)selfChanges user availability without discarding the value.
IsDisabled()booleanReads the requested disabled state.
Destroy()nilRemoves this control and its subscriptions; safe to repeat.

Behavior and limitations#

Toggle flips active state on a fresh key press. Hold is active from press until release. Always is active while its control is available and the client has focus, without requiring a bound key press.

Capture is exclusive within the loaded library instance. Escape cancels; Backspace/Delete clears the binding. The captured press does not activate a shortcut. BeginCapture while already capturing cancels and returns false.

Invalid constructor bindings assert; invalid SetValue returns false. Keyboard bindings are not a touch shortcut system. Processed input, text focus or lost client focus prevents ordinary shortcut activation.

Callback reports rebinding or a notifying mode change. OnActivate reports runtime activation. SetValue(key, false) may release an active binding via OnActivate(false).

Modal/hide/minimize suppress input and cancel capture. Toggle/Hold wait for a fresh press after availability returns; Always resumes.

Only key and mode persist. Load/Reset do not replay OnActivate. Capture, pressed and active state are transient.

Supported bindings exclude Unknown, Escape, Backspace, Delete, and gamepad Button/DPad/Thumbstick keys. Those reserved keys cannot be set as ordinary shortcuts. Invalid modes or non-boolean notify values assert.