natiny.input.set_mouse_capture

Lua
natiny.input.set_mouse_capture(enabled)

Enables or disables mouse capture. While captured, the cursor is hidden and mouse movement continues past the window edges.

Parameters

Name Type Description
enabled boolean true to capture the mouse, false to release it

Example

Lua
if natiny.input.get_mouse_button_pressed(natiny.input.MOUSE_BUTTON_LEFT) then
    natiny.input.set_mouse_capture(true)
end

Notes

  • A window must exist before this function is called. Otherwise it does nothing.
  • Escape releases the mouse. In a browser, changing tabs can also release it; use natiny.input.get_mouse_captured to read the state.
  • In a browser, enabling capture may be deferred until the next user gesture, and a refused request is retried on the next click. A browser refuses one for about a second after Escape released the last.
  • Mouse movement is 0 on the frame capture changes and on the following frame.