class Controls
package fivem.client.core
Keyboard, mouse and gamepad input.
Two distinct mechanisms live here, and picking the right one matters:
- Key mappings (
bind) register a command the player can rebind in the game's own settings menu. They work while the game window has focus, cost nothing per frame, and are the right default. - Control polling (
isPressedand friends) reads the game's own controls each frame. Necessary for held keys, analogue axes and anything that has to react mid-frame — but it only works inside a per-frame loop.
Controls.bind("openInventory", "Open inventory", "i", () -> inventory.open());
Thread.everyFrame(() -> {
if (Controls.isJustPressed(Context)) interact();
});Static variables
staticinlineread onlyDEFAULT_PAD:Int = 0
Pad index 0 — keyboard and the primary gamepad. Every method here defaults to it.
Static methods
staticbind(commandName:String, description:String, defaultKey:String, onPressed:() ‑> Void, ?onReleased:() ‑> Void):Void
Binds a key to an action, showing up in the player's keybinding settings so they can change it.
Parameters:
commandName | A unique command name; must not collide with another resource's. |
|---|---|
description | The label shown in the settings menu. |
defaultKey | The default binding, e.g. |
onPressed | Runs when the key goes down. |
onReleased | Runs when it comes back up, if given. |
staticinlinedisable(control:Control, padIndex:Int = DEFAULT_PAD):Void
Stops the game reacting to a control. Only lasts one frame, so call it from a per-frame loop for as long as the control should stay disabled.
staticinlinedisableAll(padIndex:Int = DEFAULT_PAD):Void
Disables every control for one frame. Also one-frame — loop it.
staticinlineisDisabledPressed(control:Control, padIndex:Int = DEFAULT_PAD):Bool
As isPressed, but also true for a control you disabled this frame.
Disabling a control stops the game reacting to it while leaving it readable by script — the standard way to repurpose a key without the player's character also acting on it.
staticinlineisJustPressed(control:Control, padIndex:Int = DEFAULT_PAD):Bool
Whether a control went down this frame.
staticinlineisJustReleased(control:Control, padIndex:Int = DEFAULT_PAD):Bool
Whether a control came up this frame.
staticinlineisPressed(control:Control, padIndex:Int = DEFAULT_PAD):Bool
Whether a control is currently held.
staticinlinevalue(control:Control, padIndex:Int = DEFAULT_PAD):Float
An analogue control's value, -1 to 1.
staticwhileHeld(control:Control, ?body:(elapsedMs:Int) ‑> Void, padIndex:Int = DEFAULT_PAD):Int
Runs body every frame while control is held, and resolves once it
is released. Returns how long it was held, in milliseconds.
Useful for hold-to-act interactions:
Thread.create(() -> {
var heldMs = Controls.whileHeld(Context, elapsed -> Ui.showHelp('Hold... $elapsed'));
if (heldMs > 2000) forceOpen();
});