Mouse API

Category: API Reference

Simulate mouse movements, clicks, and scrolling with human-like behavior.

Functions

move_to

mouse:move_to(x: number, y: number, duration_ms: number?) -> ()

Move mouse to position with human-like behavior.

Parameters:

ParameterTypeRequiredDescription
xnumberYesTarget X coordinate
ynumberYesTarget Y coordinate
duration_msnumberNoMovement duration in milliseconds

Example:

mouse:move_to(400, 300)  -- Move to (400, 300)
mouse:move_to(400, 300, 500)  -- Move over 500ms

left_click

mouse:left_click(x: number, y: number, duration_ms: number?) -> ()

Left click at position.

Parameters:

ParameterTypeRequiredDescription
xnumberYesClick X coordinate
ynumberYesClick Y coordinate
duration_msnumberNoMovement duration before click

Example:

mouse:left_click(300, 250)

right_click

mouse:right_click(x: number, y: number, duration_ms: number?) -> ()

Right click at position.

Parameters:

ParameterTypeRequiredDescription
xnumberYesClick X coordinate
ynumberYesClick Y coordinate
duration_msnumberNoMovement duration before click

click

mouse:click() -> ()

Click at current mouse position.


position

mouse:position() -> Point

Gets current mouse position.

Returns:

  • Point - Current position with x, y

Example:

local x, y = mouse:position()
logger:info("Mouse at: " .. x .. ", " .. y)

scroll

mouse:scroll(delta: number, x: number, y: number) -> ()

Scroll vertically.

Parameters:

ParameterTypeRequiredDescription
deltanumberYesPositive to scroll up, negative to scroll down
xnumberYesX position to scroll at
ynumberYesY position to scroll at

Example:

mouse:scroll(5, 400, 300)  -- Scroll up 5 notches
mouse:scroll(-3, 400, 300)  -- Scroll down 3 notches

scroll_horizontal

mouse:scroll_horizontal(delta: number, x: number, y: number) -> ()

Scroll horizontally.

Parameters:

ParameterTypeRequiredDescription
deltanumberYesPositive for right, negative for left
xnumberYesX position
ynumberYesY position

set_speed

mouse:set_speed(multiplier: number) -> ()

Set mouse movement speed multiplier.

Parameters:

ParameterTypeRequiredDescription
multipliernumberYesSpeed multiplier (1.0 = normal)

Example:

mouse:set_speed(0.5)  -- Half speed
mouse:set_speed(2.0)  -- Double speed

get_speed

mouse:get_speed() -> number

Get current speed multiplier.

Returns:

  • number - Speed multiplier

is_in_window

mouse:is_in_window(x: number, y: number) -> boolean

Check if position is in game window.

Parameters:

ParameterTypeRequiredDescription
xnumberYesX coordinate
ynumberYesY coordinate

Returns:

  • boolean - True if in window

track

mouse:track(entity: LuaNpc | LuaPlayer | LuaGameObject | LuaGroundItem, options?: table) -> ()

Start tracking a live entity: a dedicated thread keeps moving the mouse to hover over the entity. Tracking continues until the entity is no longer valid (e.g. despawns, moves out of view), another mouse API call is made (move_to, left_click, right_click, click, scroll, etc.), or an optional timeout is reached. Call mouse:stop_track() to stop without performing another action.

Parameters:

ParameterTypeRequiredDescription
entityLuaNpc | LuaPlayer | LuaGameObject | LuaGroundItemYesThe entity to track
optionstableNo{ timeout = number } — stop tracking after this many milliseconds

Example:

local cow = npcs:nearest("Cow")
if cow then
    mouse:track(cow)                    -- Track until entity invalid or another mouse call
    mouse:track(cow, { timeout = 5000 }) -- Track for up to 5 seconds
end

-- Later: stop tracking without clicking
mouse:stop_track()

stop_track

mouse:stop_track() -> ()

Stop mouse tracking without performing any other mouse action. Has no effect if no entity is currently being tracked.


Per-entity methods: LuaNpc, LuaPlayer, LuaGameObject, LuaGroundItem, LuaComponent, and LuaItem each have move_mouse_to() and track(). See NPC, Player, GameObject, GroundItem, Component, and Item.


Common Patterns

Safe Clicking

local function safe_click(x, y)
    if mouse:is_in_window(x, y) then
        mouse:left_click(x, y)
        return true
    else
        logger:warn("Click target out of bounds: " .. x .. ", " .. y)
        return false
    end
end

Right-Click Menu

local function right_click_and_select(x, y, action_text)
    mouse:right_click(x, y)
    sleep(300)  -- Wait for menu
    
    local menu_items = menu:items()
    for _, item in ipairs(menu_items) do
        if item:action():find(action_text) then
            mouse:left_click(
                menu:slot_center(item:index()).x,
                menu:slot_center(item:index()).y
            )
            return true
        end
    end
    
    return false
end

Random Click Area

local function click_random_in_area(x1, y1, x2, y2)
    local x = math.random(x1, x2)
    local y = math.random(y1, y2)
    
    -- Add slight movement delay for human-like behavior
    local delay = math.random(50, 150)
    mouse:left_click(x, y, delay)
end

-- Click random point in component
local comp = components:get(149, 0)
click_random_in_area(
    comp:x(),
    comp:y(),
    comp:x() + comp:width(),
    comp:y() + comp:height()
)

Careful Bank Clicking

local function click_bank_item(item)
    local x = item:x()
    local y = item:y()
    local w = item:width()
    local h = item:height()
    
    -- Click center with random offset
    local center_x = x + w / 2
    local center_y = y + h / 2
    
    local offset_x = math.random(-w * 0.25, w * 0.25)
    local offset_y = math.random(-h * 0.25, h * 0.25)
    
    mouse:left_click(center_x + offset_x, center_y + offset_y, 100)
end