Keyboard, mouse and game controls
| Input | API | Binding |
|---|---|---|
| Keyboard shortcut | keyDown, keyUp and KeyCodes |
A specific keyboard key. |
| Mouse input | mouseMove, mouseButton, mouseWheel |
Pointer position, buttons and scrolling. |
| GTA action | Control natives and Control |
GTA’s current keyboard or controller binding for an action. |
Input handlers run in client scripts. Send a server event when an interaction needs server validation or changes shared state.
Keyboard shortcuts
Section titled “Keyboard shortcuts”keyDown(key, modifiers) fires once when a key is pressed. Holding it does not
produce repeated events. keyUp(key, modifiers) reports its release.
This example emits a local journal:toggle event when the player presses Ctrl+J.
Connect that event to your journal interface:
// @ts-check/// <reference types="@revomp/types-client" />import * as revo from 'revo-client';
revo.on('keyDown', (key, modifiers) => { if (key !== revo.KeyCodes.J) return; if ((modifiers & revo.InputModifier.Control) === 0) return; if (revo.isCursorVisible()) return;
revo.emit('journal:toggle');});modifiers is a bitmask. Use & to check InputModifier.Control, Shift or
Alt while allowing other flags to be present. Caps Lock, Num Lock and mouse
buttons also have modifier flags.
KeyCodes uses Windows virtual-key values. The key events do not distinguish
left and right Shift, Control or Alt. Punctuation names follow the US keyboard
layout. For text entry, use an input element in a WebView so character conversion
and keyboard layouts are handled by the browser.
Returning a value from a key handler does not consume the key or cancel its GTA action. Use control natives when you need to suppress a game action.
Mouse input
Section titled “Mouse input”| Event | Arguments |
|---|---|
mouseMove |
x, y, modifiers, leave |
mouseButton |
button, released, x, y, modifiers |
mouseWheel |
delta, x, y, modifiers |
Coordinates are pixels relative to the game window’s client area, with the origin
at the top left. MouseButton provides Left, Middle and Right.
For button events, released is false on a press and true on release.
When mouseMove reports leave === true, the pointer has left the window.
The coordinates in that event are placeholders. Clear hover state instead of
treating it as movement to (0, 0).
mouseWheel supplies the raw signed wheel delta. Preserve its magnitude when
implementing scrolling. WebView interfaces can use their normal browser mouse
events.
GTA control bindings
Section titled “GTA control bindings”Use Control values with GTA control natives. For example, Control.Context
selects the context action and follows its current game binding, including
controller input. KeyCodes.E selects a keyboard key independently of that
binding.
The first argument to the control natives below is the input group. These
examples use group 0 for gameplay controls.
| Native | Use |
|---|---|
natives.isControlJustPressed(0, action) |
Detect a new press. |
natives.isControlPressed(0, action) |
Check whether the action is held. |
natives.getControlNormal(0, action) |
Read an analog input value. |
natives.isDisabledControlJustPressed(0, action) |
Detect a press after disabling the action’s normal game behavior. |
Poll game controls with everyTick(). This example reserves the context action
while canInteract() returns true, then calls interact() on a press:
// @ts-check/// <reference types="@revomp/types-client" />/// <reference types="@revomp/types-natives" />import * as revo from 'revo-client';import * as natives from 'natives';
/** * @param {() => boolean} canInteract * @param {() => void} interact */export function bindContextAction(canInteract, interact) { let focused = true;
/** @param {boolean} value */ function onFocus(value) { focused = value; }
revo.on('windowFocus', onFocus);
const tick = revo.everyTick(() => { if (!focused || revo.isCursorVisible() || natives.isPauseMenuActive()) return; if (!canInteract()) return;
natives.disableControlAction(0, revo.Control.Context, true); if (natives.isDisabledControlJustPressed(0, revo.Control.Context)) { interact(); } });
return () => { revo.clearEveryTick(tick); revo.off('windowFocus', onFocus); };}Use canInteract() to check your current interaction target and interface state.
Call the returned function to remove the binding.
disableControlAction() must run each frame while the action is reserved.
Stopping those calls releases it. The example uses the disabled-control query
to read the press after suppressing GTA’s normal action.
Custom script actions have no API for adding bindings to the pause menu. Reuse an appropriate GTA action or provide a binding selector in your own interface. If you display a control prompt, account for the player’s current binding and input device.
Menus and focus changes
Section titled “Menus and focus changes”The pause menu suspends new script keyboard presses and mouse events. Releases for keys pressed earlier can still arrive. The built-in console consumes its keyboard input.
Focusing a resource WebView does not suppress script shortcuts. Track your interface state and skip gameplay handlers while typing. The shortcut example also skips input while the cursor is visible. Cursor visibility alone does not describe every interface state.
windowFocus(focused) reports focus changes such as Alt+Tab. On focus loss,
tracked keys receive keyUp with zero modifiers before windowFocus(false).
Use keyDown for one-shot actions. Clear held-button or drag state when focus
is lost.