Keybind

Captures a key from the user, then calls you every time it is pressed.

The smallest keybind#

Luau
main:Keybind({
    Text = "Toggle aimbot",
    Callback = function()
        aimbot = not aimbot
    end,
})

Click the control, press a key, and it is bound. Callback runs on every press of that key from then on. While it is listening, Escape or a mouse click cancels and keeps the old key.

Preview

My Script

v1.0

Panic key

Building it up#

Pick a starting key:

Luau
main:Keybind({
    Text = "Toggle aimbot",
    Default = Enum.KeyCode.E,
    Callback = toggleAimbot,
})

React to rebinding. Changed fires when the user picks a new key, which is separate from that key being pressed:

Luau
main:Keybind({
    Text = "Toggle aimbot",
    Default = Enum.KeyCode.E,
    Callback = toggleAimbot,
    Changed = function(key)
        print("now bound to", key.Name)
    end,
})

Remember it:

Luau
main:Keybind({
    Text = "Toggle aimbot",
    Default = Enum.KeyCode.E,
    Save = "aimbotKey",
    Callback = toggleAimbot,
})

Every option#

OptionTypeDefaultWhat it does
TextreqstringThe label.
Callbackfunction(EnumItem)Called with the bound key each time it is pressed. Not called when Roblox has already handled the press, such as while typing in a text box.
DefaultEnumItem | stringThe starting key: Enum.KeyCode.E, or the name "E".
Changedfunction(EnumItem)Called when the user binds a different key.
DescriptionstringA quieter second line.
IconstringAn icon shown before the label.
HoverColorColor3 | stringThe border colour on hover. A theme role name works too.
HoverFillColor3 | stringThe background colour on hover, or a theme role name.
Savestring | booleanPersist the bound key. true derives a storage key from the section and label.
TooltipstringShown while the pointer is over the control.
DisabledbooleanfalseRefuses input and dims the control.
DisabledReasonstringShown as a tooltip while it is disabled.

Methods#

MethodReturnsWhat it does
Get()EnumItem or nilThe currently bound key
Set(key)true, or false, reasonRebinds it. Takes a KeyCode, a key name, or nil to unbind.
Luau
local bind = main:Keybind({ Text = "Toggle", Default = Enum.KeyCode.E })
 
bind:Get()                        --> Enum.KeyCode.E
bind:Set(Enum.KeyCode.RightAlt)   -- rebinds
bind:Set("RightAlt")              -- the same, by name
bind:Set(nil)                     -- unbound; the control reads "None"

Set fires Changed, not Callback. Pass true as a second argument to skip Changed too.

The window has a separate keybind

The key that hides and shows the whole window is set on Ember.new with its Keybind option, and defaults to RightShift. A Keybind control is for your script's own actions.