Skip to content

clickMouse

Clicks at the given viewport coordinates using trusted input, so the renderer synthesizes a real click (or contextmenu, for the right button) with isTrusted === true.

The low-level primitive: one click at one point, with no waiting for any effect — callers poll their own readiness signal. Prefer clickElement for element-relative clicks.

A real context menu actually opens, so a suite driving a right click must close it (or remove the leftover .menu element) before the next test.

On mobile the button model does not survive the port: touch has no buttons, so 'left' (the default) is a tap, 'right' is the long-press that opens Obsidian Mobile’s context menu, and 'middle' throws.

Import:

import { clickMouse } from 'obsidian-dev-utils/obsidian/trusted-input';

Signature:

function clickMouse(params: ClickMouseParams): Promise<void>

Parameters:

ParameterTypeDescription
paramsClickMouseParamsThe viewport coordinates to click at, the button to press and any modifiers to hold.

Returns: Promise<void> — A Promise that resolves once the click has been injected.


Links to this page: