Skip to main content

Mouse

The standard pointer input device for desktops and laptops users.

Querying Mouse State

getMPos

Get the position of the mouse.

mouseX, mouseY = getMPos()
ReturnTypeNote
mouseXnumber
mouseYnumber

isMDown

Check if a mouse button is down.

isButtonDown = isMDown(buttonId)
ParameterTypeDefaultNote
buttonIdnumber⚠️ required1: primary (left). 2: middle (wheel). 3: secondary (right). further values are mouse dependent.
ReturnTypeNote
isButtonDownboolean

Listening For Mouse Events

_mousepressed

Triggered when a mouse button is pressed, or if the screen was touched.

function _mousepressed(x, y, buttonId, isTouch)
--Logic executed when the event is triggered
end
ParameterTypeNote
xnumber
ynumber
buttonIdnumber1: primary (left). 2: middle (wheel). 3: secondary (right). further values are mouse dependent.
isTouchboolean

_mousemoved

Triggered when the mouse is moved, or if a screen touch was moved.

function _mousemoved(x, y, deltaX, deltaY, isTouch)
--Logic executed when the event is triggered
end
ParameterTypeNote
xnumber
ynumber
deltaXnumbersince last _mousemoved call.
deltaYnumbersince last _mousemoved call.
isTouchboolean

_mousereleased

Triggered when a mouse button is released, or if the screen was no longer touched.

function _mousereleased(x, y, buttonId, isTouch)
--Logic executed when the event is triggered
end
ParameterTypeNote
xnumber
ynumber
buttonIdnumber1: primary (left). 2: middle (wheel). 3: secondary (right). further values are mouse dependent.
isTouchboolean

_wheelmoved

Triggered when the mouse wheel is moved.

function _wheelmoved(deltaX, deltaY)
--Logic executed when the event is triggered
end
ParameterTypeNote
deltaXnumberhorizontal movement. positive values indicate movement to the right.
deltaYnumbervertical movement. positive values indicate upward movement.