Knowledge from the fieldRedM

SetNuiFocus(focus, cursor) is two independent bools; snapshot & restore prior focus on close or you leak input

learning:54

SetNuiFocus(focus, cursor) is two independent bools; snapshot & restore prior focus on close or you leak input

Context

SetNuiFocus takes two independent bools: (grabKeyboard/mouse focus, show mouse cursor). SetNuiFocusKeepInput is a separate toggle that lets game input through while NUI is focused. Robust UIs must save and restore the prior focus state.

The pattern

-- before opening:
local prevFocus     = IsNuiFocused()
local prevKeepInput = IsNuiFocusKeepingInput()
SetNuiFocus(true, not hideCursor)
-- on close:
SetNuiFocus(false, false)
SetNuiFocusKeepInput(prevKeepInput)

The trap

Hard-coding SetNuiFocus(false, false) on close (without restoring) clobbers focus that another open NUI still needs, or leaves the cursor/focus stuck so the player can't move. The two bools are orthogonal — SetNuiFocus(true, false) is focus-without-cursor, valid and common.

Verified

Save/restore in input/client.lua:48-63; menu open/soft-hide save/restore in menu/client.lua:711-719 and :828-840. SET_NUI_FOCUS_KEEP_INPUT is a bare stub; the two-bool semantics and save/restore discipline are undocumented.


Tags: nui, setnuifocus, keepinput, cursor, focus, ui
Category: natives
Source: jo_libs-fleet
Created: 2026-05-31T09:40:17.402Z

Back to documentation