Skip to content

Mouse

Overview

The Mouse table contains functions which provide data belonging to the user's mouse input.

This data includes:

  • Mouse availability (false on Mobile devices)
  • Mouse position
  • TODO position with UI scaling applied
  • TODO mouse button states

Info

The mouse position:

  • is relative to the top-left of the game window, and
  • updates only when the mouse is within the bounds of the game window.

Examples

if Mouse.IsAvailable() then
    -- A Vector2 containing the mouse X & Y position
    local xy = Mouse.GetPosition()
    -- Or separately
    local x = Mouse.GetX()
    local y = Mouse.GetY()
end

Functions

IsAvailable

function Mouse.IsAvailable() -> Boolean

Returns whether mouse data is available on the current platform.

Returns Description
Boolean Whether mouse data can be polled on the current platform.
Returns false on Mobile devices, and true on all others.

Example

if Mouse.IsAvailable() then
    local mousePositionXY = Mouse.GetPosition()
else
    log("No mouse data available")
end

GetPosition

function Mouse.GetPosition() -> Vector2?

Returns the current mouse X & Y position, if available.

Returns Description
Vector2? The current mouse position.
Returns nil on Mobile devices.

Example

if Mouse.IsAvailable() then
    local mousePositionXY = Mouse.GetPosition()
end

GetX

function Mouse.GetX() -> Integer?

Returns the current mouse X position, if available.

Returns Description
Integer? The current X position of the mouse.
Returns nil on Mobile devices.

Example

if Mouse.IsAvailable() then
    local mousePositionX = Mouse.GetX()
end

GetY

function Mouse.GetY() -> Integer?

Returns the current mouse Y position, if available.

Returns Description
Integer? The current Y position of the mouse.
Returns nil on Mobile devices.

Example

if Mouse.IsAvailable() then
    local mousePositionY = Mouse.GetY()
end