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:
InputSim::mouse→Mousefor pointer operations (click,drag,scroll,down/up).InputSim::keyboard→Keyboardfor key operations (press,chord,down/up,type_text).
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§
- Click
Options - Options for
Mouse::click_with. - Drag
Options - Options for
Mouse::drag_with. - Input
Sim - 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.
- Scroll
Delta - Direction and magnitude of a scroll event, in platform “ticks” (typically
one notch of a physical scroll wheel). Positive
dyscrolls content downward (i.e. moves the viewport up); positivedxscrolls right.
Enums§
- Anchor
- Where on an element to land a pointer event.
- Click
Target - Explicit target for
Mouse::click_with: either a raw point or an element to anchor against. - Key
- A keyboard key.
- Mouse
Button - A mouse button.
Traits§
- Input
Provider - Platform backend trait for synthesised user input.
- Into
Point - A target that can be lowered to a screen
Point.