Keybind (tm.keybind)
Context: client only.
One call registers the command, maps the key (RegisterKeyMapping) and wires press and release handlers (RegisterCommand). The handlers stay in the calling resource.
tm.keybind({
name = 'openInventory',
description = 'Open inventory',
defaultKey = 'TAB',
onPressed = function(source, args, raw, keybind) end,
})tm.keybind(options) is the same as tm.keybind.register(options) and returns a RegisteredKeybind, or nil (with a logged error) when no name was given.
Options
| Field | Aliases | Default | Description |
|---|---|---|---|
name | command | required | Command name. A leading + or - is ignored. |
description | help | the name | Label in the GTA key settings. |
defaultMapper | default_map | 'keyboard' | Input device. |
defaultKey | default_key | '' (unbound) | Default key such as 'E', 'F5', 'LSHIFT'. |
onPressed | onPress, onDown | none | Called on key down. |
onReleased | onUp | none | Called on key up. Makes the bind a +name and -name pair. |
useExistingCommand | false | Skip RegisterCommand when the command is registered elsewhere (the key is still mapped). |
Handlers receive what RegisterCommand gives them: (source, args, raw, options). An error inside a handler is logged and never escapes into the command system.
Behavior
- Press only: one command
name. WithonReleased: commands+nameand-name, mapped through+name. - The return value is
{ command, release?, description, defaultMapper, defaultKey }(commandis'+name'for a pair). - Registering the same name again replaces the handlers and never registers a second command or mapping. A bind that started as press only stays press only (the release handler is ignored with a warning).
- Players can rebind the key in their GTA settings, the default is only the starting point.
Other functions
| Function | Description |
|---|---|
tm.keybind.isRegistered(name) | True when this resource has an active bind with that name. |
tm.keybind.unregister(name) | Stops the handlers from running. The game cannot remove a command or key mapping before the resource stops, so they stay registered. Registering the name again turns it back on. |
tm.keybind({
name = 'aimMode',
defaultKey = 'LMOUSEBUTTON',
defaultMapper = 'MOUSE_BUTTON',
onPressed = function() TriggerEvent('aim:start') end,
onReleased = function() TriggerEvent('aim:stop') end,
})Editors and the input lock
While an in-world editor holds tm.inputlock (zone creators, gizmos), key presses are ignored so an editor that reads a key does not also trigger the inventory or radial. Releases still run, so a key that was already down never sticks. A binding that must keep working inside an editor sets ignoreEditorLock = true.