obsidian/desktop-trusted-input
Desktop-only trusted input helpers that drive the real Electron renderer via webContents.sendInputEvent, so keystrokes and pointer moves flow through the same trusted input pipeline a real user produces (unlike untrusted dispatchEvent, which CodeMirror and the CSS :hover engine ignore).
These are the importable-module twins of the base helpers the obsidian-integration-testing harness seeds into the lib bag; the two copies are kept behaviorally in sync by hand (see the project CLAUDE.md). Desktop-only: they depend on window.electron.
Interfaces
Section titled “Interfaces”| Interface | Description |
|---|---|
| HoverElementParams | Parameters for hoverElement. |
| MoveMouseParams | Parameters for moveMouse. |
| PressKeyParams | Parameters for pressKey. |
| TypeIntoEditorParams | Parameters for typeIntoEditor. |
| UnhoverElementParams | Parameters for unhoverElement. |
Functions
Section titled “Functions”| Function | Description |
|---|---|
| hoverElement | Moves the mouse pointer to the center of an element using trusted Electron pointer input, then polls until the element actually matches :hover. Because the move is trusted, the real :hover state takes effect in the CSS engine — unlike dispatchEvent(new MouseEvent('mouseover')), which is untrusted and never sets :hover. It targets the single window’s global pointer, so only one element is hovered at a time. |
| moveMouse | Moves the mouse pointer to the given web-contents coordinates using a trusted Electron pointer move. A trusted move updates the real pointer state in the CSS engine, so :hover rules genuinely apply. This is the low-level primitive: it performs a single move and does not wait for any state to settle (callers poll their own readiness signal). Prefer hoverElement / unhoverElement for element-relative moves. |
| 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. |
| typeIntoEditor | Types text into a CodeMirror Editor using trusted Electron keyboard input. This focuses the editor (caret to end) and presses every code point of text via pressKey — the same trusted sequence a real user produces — so the text reaches the document only if the editor genuinely holds focus. After injecting the keystrokes it polls until the document reflects the input, or a bounded timeout elapses (the expected outcome when the editor is read-only or focus was stolen). |
| unhoverElement | Moves the mouse pointer to a point just outside an element’s bounding box using a trusted Electron pointer move, then polls until the element no longer matches :hover. The inverse of hoverElement. When an element spans the full viewport (no point outside its box is reachable), use moveMouse directly to move the pointer to a known empty coordinate instead. |