pressKey
Presses a single key (optionally with modifiers) using trusted Electron keyboard input, firing the full real key pipeline — keydown → keypress → beforeinput → input → keyup.
It injects a trusted keyDown → char → keyUp 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): voidParameters:
| Parameter | Type | Description |
|---|---|---|
params | PressKeyParams | The key to press and any modifiers to hold. |
Returns: void
Links to this page: