Keybinds
Keybind - a key the player can rebind in GTA's settings, whose default key the server owner can change in ai-core's admin panel.
Every key a script listens to is a Keybind: the player can change it in GTA's settings (Settings > Key Bindings > FiveM), the server owner can change its default in ai-core's admin panel (Keybinds tab), and nothing polls keys every frame.
new Keybind
Registers a rebindable key. The default key comes from ai-core's admin panel when the owner set one there, else from defaultKey. The lib registers the key mapping once ai-core answered (one round trip at start); without ai-core it uses defaultKey at once.
Side: Client · Waits: no (registration finishes in the background)
new Keybind(options: KeybindOptions)local key = aiLib.Keybind.new(options)Parameters
Prop
Type
KeybindOptions
Prop
Type
The hint type is KeyHintWhen.
Members
Prop
Type
Example
import { createLocale, Keybind, NuiScreen } from "@aicore-fivem/lib/client";
const Locale = createLocale<typeof import("../../locales/en.json")>();
const screen = new NuiScreen("tablet");
const openKey = new Keybind({
name: "mytablet_open",
description: Locale("KEYBIND_OPEN_TABLET"),
defaultKey: "F5",
hint: "foot",
icon: "tablet-screen-button",
hintLabel: Locale("HINT_TABLET"),
onPressed: () => {
if (screen.isOpen) return;
// Tell the page which key closes it again.
screen.open({ action: "open", data: { closeKey: openKey.currentKey } });
},
});
// While cuffed the key does nothing.
export const setCuffed = (cuffed: boolean): void => openKey.disable(cuffed);The mapping command carries the key: +<name>_<key> (+mytablet_open_F5). When the owner changes the default in the panel, the new key gets its own mapping that every player receives, and the old one stops acting. FiveM keeps old mappings and each player's own binding per command, which is why the key is part of the name. Another resource that needs this keybind's key asks ai-core's client export GetKeybindKey(name).
Keep name stable: renaming it makes a new keybind, and every player loses the key they bound to the old one. Never make two keybinds with the same name, even in different resources.