Skip to content

pressKey

Presses a single key (optionally with modifiers) using trusted Electron keyboard input, firing the full real key pipeline — keydownkeypressbeforeinputinputkeyup.

It injects a trusted keyDowncharkeyUp sequence, delivered to the window’s DOM-focused element — unlike dispatchEvent(new KeyboardEvent(...)), which is untrusted and ignored by CodeMirror. Use it for special keys ('Enter', 'Escape', 'Tab', arrow keys) and modifier combinations. It does not poll for any effect; the caller focuses the target first, then awaits the expected effect.

Import:

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

Signature:

function pressKey(params: PressKeyParams): void

Parameters:

ParameterTypeDescription
paramsPressKeyParamsThe key to press and any modifiers to hold.

Returns: void


Links to this page: