Skip to content

st.addKeybind — Keybind Registration (Client) ​

lua
---@class KeybindProps
---@field name string              Internal name (must be unique)
---@field description string       Shown in key bindings menu
---@field defaultMapper? string    Input mapper (default: 'keyboard')
---@field defaultKey? string       Default key
---@field secondaryKey? string     Optional secondary key
---@field secondaryMapper? string
---@field disabled? boolean
---@field onPressed? fun(self)     Called on key press
---@field onReleased? fun(self)    Called on key release

local bind = st.addKeybind({
    name = 'myResourceAction',
    description = 'Gør noget',
    defaultKey = 'E',
    onPressed = function(self)
        print('Tastet!')
    end,
    onReleased = function(self)
        print('Sluppet!')
    end,
})

-- Control the keybind later
bind.disabled = true           -- disable without unregistering
bind:disable(true)             -- same via method
bind:isControlPressed()        -- boolean, true while held
bind.currentKey                -- string, current mapped key
bind.isPressed                 -- boolean raw state