Keybinds
Shiva provides a client-side Keybinds global for registering player-configurable key bindings. Never call RegisterKeyMapping directly — using Keybinds adds conflict detection and clean unregistration.
Registering a Keybind
lua
Keybinds.register(id, label, defaultKey, onPressed, onReleased)lua
Keybinds.register('mymodule:fish', 'Start Fishing', 'E',
function()
-- key pressed
TriggerServerEvent('net:mymodule:startFishing')
end,
function()
-- key released (optional, can be nil)
end
)| Parameter | Type | Description |
|---|---|---|
id | string | Unique identifier, use modulename:action format |
label | string | Human-readable description shown in FiveM keybind settings |
defaultKey | string | Default key (e.g. 'E', 'F', 'G') |
onPressed | function | Called when the key is pressed |
onReleased | function|nil | Called when the key is released (optional) |
Conflict Detection
If two modules register the same defaultKey, the second registration logs a warning and clears the default so the player can assign it manually in their FiveM settings:
[WARN] keybinds: Default key conflict — clearing default
{ id = 'mymodule:fish', key = 'E', conflictsWith = 'othermodule:interact' }Players can always rebind any key in Settings → Key Bindings → FiveM.
Unregistering a Keybind
lua
Keybinds.unregister('mymodule:fish')Call this in your module's stop handler to clean up when the module unloads.
Checking Registration
lua
if Keybinds.isRegistered('mymodule:fish') then
-- already registered
endFull Example — Module with Keybinds
lua
-- boot.lua (client-side)
AddEventHandler('module:boot', function()
Keybinds.register('mymodule:openMenu', 'Open Fishing Menu', 'F6',
function()
View.panelShow('fishing-menu', {})
end
)
Keybinds.register('mymodule:castLine', 'Cast Fishing Line', 'E',
function() TriggerServerEvent('net:mymodule:cast') end,
function() TriggerServerEvent('net:mymodule:reel') end
)
end)
AddEventHandler('module:stop', function()
Keybinds.unregister('mymodule:openMenu')
Keybinds.unregister('mymodule:castLine')
end)API Reference
| Method | Description |
|---|---|
Keybinds.register(id, label, defaultKey, onPressed, onReleased) | Register a keybind with conflict detection |
Keybinds.unregister(id) | Remove a registered keybind |
Keybinds.isRegistered(id) | Returns true if the id is currently registered |
Client-only
Keybinds is a client-side global. It is not available in server scripts.