OnMouseButton
A mouse button went down or came up while the player’s cursor is up.
Every press (pressed is true) and release (false) of the left, right or middle button while the cursor is up, with
the pointer’s place in the UI space (GetScreenSize: 1080 rows high) - what a menu needs for a drag, a slider or a
button that acts on the release. A press this heard always gets its release: if the cursor goes away with the button
still down (one of the game’s own menus, the cursor key), the release comes right before OnCursorChange. A release
whose press came before the cursor was up is not reported.
The button is only observed - it also reaches what is on screen under the pointer - unless the script holds the mouse
with SetMouseCapture: then it is the script’s alone.
Syntax
Section titled “Syntax”function OnMouseButton(button, pressed, x, y) -- ...end| Parameter | Type | |
|---|---|---|
button |
string | "left", "right" or "middle" |
pressed |
boolean | true when the button went down, false when it came up |
x |
number | the pointer’s place across, in the UI space |
y |
number | the pointer’s place down, in the UI space (0 at the top, 1080 at the bottom) |
Returns
Section titled “Returns”nothing
Example
Section titled “Example”-- a slider of the script's own: 300 wide at 100, 500local dragging = falselocal function setFromX(x) local v = math.max(0, math.min(1, (x - 100) / 300)) SetUiSize("slider_fill", 300 * v, 20)endfunction OnMouseButton(button, pressed, x, y) if button ~= "left" then return end if pressed and x >= 100 and x <= 400 and y >= 500 and y <= 520 then dragging = true setFromX(x) elseif not pressed then dragging = false endendfunction OnMouseMove(x, y) if dragging then setFromX(x) endendSee also
Section titled “See also”OnMouseMove · OnMouseWheel · OnCursorClick · SetMouseCapture · the The game’s UI for a script group of the index
