Skip to content

SetMouseCapture

Takes the mouse for a menu of the script’s own, or gives it back.

What SetKeyboardCapture does for the keyboard, for the mouse. While the script holds it:

  • the cursor is up, and stays up - the cursor key and SetCursorShown(false) do not take it away. One of the game’s own menus and a load still hide it meanwhile, and it comes back after them.
  • the buttons and the wheel are the script’s alone: OnMouseButton, OnCursorClick and OnMouseWheel hear them, and neither the game nor a page of the server’s interface under the pointer gets them.

The script gives it back with SetMouseCapture(false). A reload of the scripts and the end of the session give it back too. So that a player is never left without a mouse, a click the script does not hear gives it back as well. That is a click when the script defines neither OnMouseButton nor OnCursorClick, or when the one it defines fails. It can be taken whenever the session runs, even before the player is in the world (the cursor comes up once they are). true says the request was made; IsMouseCaptured says whether the script holds the mouse.

SetMouseCapture(on)
Parameter Type
on boolean true (or nothing) takes the mouse, false gives it back

boolean - true when the request was made

function OnServerEvent(name, payload)
if name == "bank.open" then
ShowUiElement("bank")
SetMouseCapture(true) -- the clicks are the bank's until it closes
elseif name == "bank.close" then
HideUiElement("bank")
SetMouseCapture(false)
end
end
function OnMouseButton(button, pressed, x, y)
if button == "left" and not pressed then bankClick(x, y) end
end

IsMouseCaptured · OnMouseButton · OnMouseWheel · SetKeyboardCapture · SetCursorShown · the The game’s UI for a script group of the index