Skip to main content

! Click a hardware mouse button (:click)

This method is available in versions after 20260805

Declaration

success, error_message = mouse_obj:click(button[, press_delay_ms])

Parameters

  • button Integer or string. Pass a value from 1 through 32 or a predefined button name. See the :down button description.
  • press_delay_ms Finite non-negative number, optional. How long to hold the button down, in milliseconds. Default: 60.

Returns

  • success Boolean. true if the click succeeds; otherwise false.
  • error_message String. The reason the click failed.

Description

Press and release the specified button. Only the target button is changed; other buttons that are already held down are not released. If the target button is already held down, the call fails to avoid disrupting a drag operation. This method yields the current Lua execution thread while holding the button. During that interval, other operations on the same mouse object return false, "hardware mouse is busy"; different mouse objects can still be operated independently.

Example

local m = assert(mouse.connect())
assert(m:click("right"))
assert(m:click(13, 100))
assert(m:click(32))
assert(m:disconnect())