Cursor and UI focus
| API | Effect |
|---|---|
view.visible = true |
Shows the WebView. |
view.focus() |
Routes keyboard input to the WebView. It must be visible. |
view.unfocus() |
Releases its keyboard focus. |
showCursor(true) |
Shows the cursor and disables GTA gameplay controls. |
showCursor(false) |
Releases the script’s cursor request. |
Showing or focusing a WebView leaves cursor visibility unchanged. Hiding or destroying it clears its focus, but also leaves the cursor request unchanged. Use both focus and cursor control for an interactive menu.
Open and close a panel
Section titled “Open and close a panel”Prepare the WebView while hidden and call await view.waitForReady() before
opening it. This waits for its JavaScript bridge. If the page has its own loading
process, also wait for an application-ready event before giving it input.
The example accepts a loaded WebView and returns a close() function. It keeps
the page loaded for the next opening:
// @ts-check/// <reference types="@revomp/types-client" />import * as revo from 'revo-client';
/** * Opens a loaded panel. Call once per opening, with no other modal UI active. * @param {revo.WebView} view */export function openPanel(view) { view.visible = true; view.focus(); revo.showCursor(true);
let closed = false;
function close() { if (closed) return; closed = true;
revo.showCursor(false); revo.off('windowFocus', onWindowFocus); view.off('panel:close', close); view.off('loadFailed', close); view.off('closed', close);
if (view.valid) { view.unfocus(); view.visible = false; } }
/** @param {boolean} focused */ function onWindowFocus(focused) { if (focused && view.valid) view.focus(); }
view.on('panel:close', close); view.on('loadFailed', close); view.on('closed', close); revo.on('windowFocus', onWindowFocus);
return close;}The page’s close button sends revo.emit('panel:close') through the WebView
bridge. Call the returned function for cancellation or a client-side error as
well. Calling it repeatedly is safe. Before explicitly destroying the WebView,
call close() and then view.destroy().
loadFailed and closed handle page-load failures and browser closure. An
application error within a loaded page needs its own error handler that requests
closure. Handle a rejected waitForReady() before calling openPanel() so a
failed load does not take control away from the player.
Coordinate interfaces
Section titled “Coordinate interfaces”Cursor visibility is shared across the client. Calls to showCursor() do not
form a stack or count how many menus are open. Use one UI controller to decide
which panel owns input and when to release the cursor.
The example assumes one interactive panel at a time. When switching panels, close the previous one before opening the next. For nested interfaces, return focus to the underlying panel and keep the cursor visible until the last one closes.
Only one WebView receives keyboard input at a time. A mouse click can move focus
to another visible WebView. Mouse targeting uses the WebView’s rectangular bounds
and zIndex, including transparent parts of the page. unfocus() releases
keyboard focus while leaving the view available for mouse input.
Client keyDown handlers still run while a resource WebView has focus. Guard
gameplay shortcuts with your UI state so typing in a form cannot trigger them.
See Keyboard, mouse and game controls for key events
and suppression of individual GTA actions.
Pause menu and Alt+Tab
Section titled “Pause menu and Alt+Tab”The pause menu temporarily hides WebViews and the script cursor, and suspends browser input. Requested WebView focus is preserved and resumes when the pause menu closes. GTA’s menu controls remain available.
Alt+Tab clears WebView focus and mouse capture. Returning to the game does not
automatically focus the previous view. The example handles windowFocus(true)
by focusing its still-open panel again. If your interface should close when the
player switches away, call close() on windowFocus(false) instead.
The built-in console can also hold the cursor visible. isCursorVisible()
reports the resulting visibility, so use your own panel state to determine
whether your interface is open.