Skip to main content

Module input

Module input 

Expand description

Input simulation: synthesised pointer and keyboard events.

Input simulation is separate from the accessibility action layer ([crate::Provider], crate::Element, crate::Locator). The two mechanisms are fundamentally different:

  • Accessibility actions (element.press(), locator.toggle()) call the platform’s a11y API directly. They work without the target window being focused or visible, are deterministic, and are the preferred way to drive a UI.
  • Input simulation (InputSim) generates OS-level pointer/keyboard events at the system event layer. Use it only for interactions that have no a11y equivalent (drag-and-drop, scroll wheels, complex shortcut sequences). Most platforms require the target window to be foregrounded and require additional permissions (Accessibility + Input Monitoring on macOS, Wayland portal grants on Linux, etc.).

There is no implicit bridge between the two: an accessibility-action failure never falls back to input simulation, and InputSim never inspects or auto-resolves the a11y tree on behalf of the caller. If you want to click an element, you compute its bounds (via the a11y API) and pass them in — see IntoPoint and point_for.

§Layout

InputSim exposes two sub-handles:

Modifier keys (Shift, Ctrl, Alt, Meta) are regular variants of Key — there is no separate Modifier type. Key::Char(c) represents the unshifted physical key; use Key::Shift explicitly for uppercase or shifted symbols (see Key for the rationale).

Structs§

ClickOptions
Options for Mouse::click_with.
DragOptions
Options for Mouse::drag_with.
InputSim
Synthesises OS-level pointer and keyboard events.
Keyboard
Keyboard operations. Obtain via InputSim::keyboard.
Mouse
Pointer operations. Obtain via InputSim::mouse.
Point
A 2D point in screen coordinates.
ScrollDelta
Direction and magnitude of a scroll event, in platform “ticks” (typically one notch of a physical scroll wheel). Positive dy scrolls content downward (i.e. moves the viewport up); positive dx scrolls right.

Enums§

Anchor
Where on an element to land a pointer event.
ClickTarget
Explicit target for Mouse::click_with: either a raw point or an element to anchor against.
Key
A keyboard key.
MouseButton
A mouse button.

Traits§

InputProvider
Platform backend trait for synthesised user input.
IntoPoint
A target that can be lowered to a screen Point.

Functions§

anchor_point
Compute a Point inside a Rect using the given Anchor.
point_for
Resolve an Element’s current bounds to a screen Point using anchor.