# setNuiFocus (Client)

> Gives or takes focus from the calling resource's interface page. With focus, the page gets the mouse and the keyboard.

- **Platform**: MY Multiplayer (MYMP)
- **Kind**: Lua Function
- **Side**: Client
- **Category**: Web interface
- **URL**: https://wiki.mymp.gg/en/setNuiFocus

## Syntax

```lua
bool setNuiFocus(bool focused [, bool cursor = true])
```

## Parameters

| Name | Type | Description |
| --- | --- | --- |
| `focused` | `bool` | `true` to give focus to this resource's page, `false` to take focus from any page. |
| `cursor` | `bool` | Whether the cursor should show with the focus. *(default: `true`)* |

## Returns

Always `true`, unless an argument is wrong.

Only one page has focus at a time. While a page has focus, the game gets neither the mouse nor the keyboard unless `setNuiKeepInput(true)` is on.

## Example

```lua
addCommandHandler("menu", function()
    setNuiFocus(true, true)
    sendNuiMessage({ action = "open" })
end)

registerNuiCallback("close", function(_, cb)
    setNuiFocus(false)
    cb()
end)
```

### Note

`cursor` currently changes nothing: with focus, the page always gets the pointer.

## See also

- [isNuiFocused (Client)](https://wiki.mymp.gg/en/isNuiFocused.md): Tells whether any interface page has focus.
- [setNuiKeepInput (Client)](https://wiki.mymp.gg/en/setNuiKeepInput.md): Chooses whether the game keeps getting the mouse and the keyboard while an interface page has focus.
- [sendNuiMessage (Client)](https://wiki.mymp.gg/en/sendNuiMessage.md): Sends a message to the interface page of the calling resource. The page receives it in the window's message event.
