LogoObsidian

Keybind

Keybinds attach keyboard shortcuts to toggles or labels for quick actions.

Playground

Example Toggle
F
Leave blank to use the default modes list.
Keep toggle value in sync
Do not show in keybind list

Usage

You can create a Keybind by calling the AddKeyPicker method on a toggle or label reference. Keybinds can hang off any element that returns a reference (for example AddToggle or AddLabel).

Arguments

local Toggle = Groupbox:AddToggle("MyToggle", {
    Text = "Example Toggle",
    Default = false,
})
 
local Keybind = Toggle:AddKeyPicker("MyKeybind", {
    Text = "Example Keybind",
    Default = "F",
    Mode = "Toggle",
})
Arg IdxArgument DescriptionTypeDefault
1Index/ID of the keybindstringnil
2Keybind configuration tabletablenil

Configuration Table

Prop

Type

Methods

You can use the following methods to interact with the keybind:

SetValue

Sets the key and mode.

Keybind:SetValue({ "F", "Toggle" })
Arg IdxArgument DescriptionTypeDefault
1Table containing { key, mode }tablenil

GetState

Returns whether the keybind is active.

local state = Keybind:GetState()
Arg IdxArgument DescriptionTypeDefault
1No arguments

SetText

Updates the keybind's text.

Keybind:SetText(text)
Arg IdxArgument DescriptionTypeDefault
1New keybind textstringnil

Update

Refreshes the keybind display.

Keybind:Update()
Arg IdxArgument DescriptionTypeDefault
1No arguments

OnClick

Sets the click callback.

Keybind:OnClick(function)
Arg IdxArgument DescriptionTypeDefault
1Callback executed on clickfunctionnil

OnChanged

Sets the change callback.

Keybind:OnChanged(function)
Arg IdxArgument DescriptionTypeDefault
1Callback executed when the keybind changesfunctionnil

Example

local Options = Library.Options
 
local Toggle = Groupbox:AddToggle("AutoFarm", {
    Text = "Enable Auto Farm",
    Default = false,
})
 
local Keybind = Toggle:AddKeyPicker("AutoFarmKey", {
    Default = "F",
    Text = "Auto Farm Key",
    Mode = "Toggle",
})
 
Options.AutoFarmKey:OnClick(function()
    print("Keybind clicked:", Options.AutoFarmKey:GetState())
end)
 
Options.AutoFarmKey:OnChanged(function()
    print("Key changed to:", Options.AutoFarmKey.Value)
end)

On this page