Keybinds and key hints
Read the key a lib Keybind was registered with, show and hide key hints on the HUD, read the hints HUDs show, and open the keys screen.
ai-core keeps track of every key that scripts register with the lib's Keybind (TypeScript) or aiLib.Keybind (Lua). That is how the admin panel's Keybinds tab can change a script's default key, how HUDs can list key hints on the left of the screen, and how the keys screen can show every key with an action.
A key hint is a short row on the HUD: a key and what it does (E Open trunk). Keybinds can declare one with their hint option. A script can also show hints for a while with ShowKeyHint, for example the controls of a tool while it is in use.
GetKeybindKey
Returns the key a lib Keybind was registered with: the key the server owner set in the admin panel's Keybinds tab, else the script's own default key. The player may still have changed it in GTA's key settings; for the key they really press, read Keybind.currentKey on your keybind instead.
Side: Client · Waits: no
GetKeybindKey(name: string): string | nulllocal key = exports['ai-core']:GetKeybindKey(name) -- string or nilParameters
Prop
Type
Returns
string: the key in upper case ("F5", "E"), or "" for a keybind without a default key. null until ai-core answered that keybind (shortly after its resource starts) and for names no running resource registered.
Example
import { Keybind, resourceExport } from "@aicore-fivem/lib/client";
import { Locale } from "common";
const core = resourceExport("ai-core");
const open = new Keybind({
name: "myscript_open",
description: Locale("KEY_OPEN"),
defaultKey: "F5",
onPressed: () => console.log("open"),
});
RegisterCommand(
"myscript_keys",
() => {
console.log(`registered with: ${core.GetKeybindKey("myscript_open") ?? "not yet"}`);
console.log(`the player presses: ${open.currentKey}`);
},
false,
);ShowKeyHint
Shows a key hint of your resource on the HUD's key hint list until you hide it. Use it for keys that matter only for a while: a tool's controls, a minigame, a camera mode. Keys your keybinds always offer belong in the hint option of the Keybind instead.
Side: Client · Waits: no
ShowKeyHint(id: string, hint: KeyHintRequest): voidexports['ai-core']:ShowKeyHint(id, hint) -- or aiLib.keyHints.show(id, hint)Parameters
Prop
Type
KeyHintRequest
See also KeyHintRequest.
Prop
Type
Returns
Nothing. A hint without a text label, or a non-string id, is ignored. A hint whose key resolves to nothing (neither keybind nor key gives a key) is kept but not listed.
Example
import { keyHints } from "@aicore-fivem/lib/client";
import { Locale } from "common";
export function startCamera(): void {
keyHints.show("camera_zoom", { label: Locale("HINT_ZOOM"), key: "SCROLL", icon: "magnifying-glass" });
keyHints.show("camera_exit", { label: Locale("HINT_EXIT"), keybind: "myscript_camera" });
}
export function stopCamera(): void {
keyHints.hide("camera_zoom");
keyHints.hide("camera_exit");
}Hints are listed in the order scripts showed them, after the hints keybinds declare. Your resource's hints are removed when it stops.
HideKeyHint
Hides one key hint your resource showed.
Side: Client · Waits: no
HideKeyHint(id: string): voidexports['ai-core']:HideKeyHint(id) -- or aiLib.keyHints.hide(id)Parameters
Prop
Type
Returns
Nothing.
Example
See the example of ShowKeyHint.
GetKeyHints
Returns the key hint rows HUDs should show right now: the hints keybinds declare for the player's situation (on foot or in a vehicle, as the server owner set them in the panel) plus the hints scripts show. A HUD reads it once at start and then follows the client event ai-core:client:keyHints, which carries the same list after every change.
Side: Client · Waits: no
GetKeyHints(): KeyHintView[]local hints = exports['ai-core']:GetKeyHints() -- array of { id, key, label, icon? }Parameters
None.
Returns
KeyHintView[], in display order. An empty array when no hint applies.
Prop
Type
Example
import { resourceExport } from "@aicore-fivem/lib/client";
import { KEY_HINTS, type KeyHintView } from "@aicore-fivem/shared";
const core = resourceExport("ai-core");
// A custom HUD's key hint list.
function draw(hints: KeyHintView[]): void {
SendNUIMessage({ action: "keyHints", data: hints });
}
draw(core.GetKeyHints());
on(KEY_HINTS.changedEvent, draw);OpenKeyboard
Opens ai-core's keys screen: a keyboard where every key that has an action is colored, with what each key does below it. Keys are shown as the player has bound them now. The radial menu's Keys entry opens it; any script can. While it is open, HUDs are hidden.
Side: Client · Waits: no
OpenKeyboard(): voidexports['ai-core']:OpenKeyboard()Parameters
None.
Returns
Nothing. Calling it while the screen is already open does nothing. The player closes it in the screen.
Example
import { resourceExport } from "@aicore-fivem/lib/client";
const core = resourceExport("ai-core");
RegisterCommand("keys", () => core.OpenKeyboard(), false);