pub async fn dispatch_key_events(events: &[TimedKeyEvent]) -> Result<(), Error>
Expand description

Simulates a sequence of key events (presses and releases) on a keyboard.

Dispatches the supplied events into a keyboard device, honoring the timing sequence that is requested in them, to the extent possible using the current scheduling system.

Since each individual key press is broken down into constituent pieces (presses, releases, pauses), it is possible to dispatch a key event sequence corresponding to multiple keys being pressed and released in an arbitrary sequence. This sequence is usually understood as a timing diagram like this:

          v--- key press   v--- key release
A: _______/^^^^^^^^^^^^^^^^\__________
   |<----->|   <-- duration from start for key press.
   |<--------------------->|   <-- duration from start for key release.

B: ____________/^^^^^^^^^^^^^^^^\_____
               ^--- key press   ^--- key release
   |<--------->|   <-- duration from start for key press.
   |<-------------------------->|   <-- duration for key release.

You would from there convert the desired timing diagram into a sequence of TimedKeyEvents that you would pass into this function. Note that all durations are specified as durations from the start of the key event sequence.

Note that due to the way event timing works, it is in practice impossible to have two key events happen at exactly the same time even if you so specify. Do not rely on simultaneous asynchronous event processing: it does not work in this code, and it is not how reality works either. Instead, design your key event processing so that it is robust against the inherent non-determinism in key event delivery.