Keys
A two-way map between readable key names ('E', 'F5') and GTA5 control IDs.
A two-way map between readable key names ('E', 'F5') and GTA5 control IDs.
lib.keys maps readable key names ('E', 'F5', 'SPACE') to the GTA5 control IDs used by
IsControlJustPressed & co. Store a friendly 'F5' in your config, resolve it to a control ID at
runtime. Shared (client + server).
local control = lib.keys.getControl('E') -- 46
CreateThread(function()
while true do
Wait(0)
if IsControlJustPressed(0, control) then print('E pressed') end
end
end)| Function | Returns | Description |
|---|---|---|
getControl(key) | ControlId? | Resolve a name or control ID to a numeric control ID. nil (+ warn) if unknown. |
getName(key) | string? | Normalize a name or control ID to its canonical name ('E', 'F5'). |
getControl(key)ControlId?nil (+ warn) if unknown.getName(key)string?'E', 'F5').| Table | Description |
|---|---|
controlNames | { [controlId] = name }. |
nameToControl | { [name] = controlId } — the reverse map. |
controlNames{ [controlId] = name }.nameToControl{ [name] = controlId } — the reverse map.Names are uppercase. The map covers A–Z (except I, J, O), 1–9, arrows, F1–F11,
modifiers (LSHIFT/LCTRL/LALT) and system keys — for example E → 46, F → 23,
SPACE → 22, ENTER → 176, ESC → 200, F5 → 166.
Control IDs are not browser keycodes or scancodes — see the FiveM controls reference.
local Config = { openKey = 'F5' }
local control = lib.keys.getControl(Config.openKey)
if not control then return end
RegisterKeyMapping('myresource:open', 'Open the menu', 'keyboard', lib.keys.getName(control))I, J and O are intentionally absent (they clash with in-game controls) — asking for them logs a
warn and returns nil. getControl is the one that truly validates against the map and returns nil
for an unknown key; getName on a string only checks the format and uppercases it, so it won't catch a
name that has no real mapping. A warn is logged on every unknown-key call, so don't call it with bad
input inside a tight loop.