Struct input_synthesis::synthesizer::TimedKeyEvent
source · pub struct TimedKeyEvent {
pub key: Key,
pub duration_since_start: Duration,
pub event_type: KeyEventType,
}
Expand description
A single key event to be replayed by dispatch_key_events_async
.
See crate::dispatch_key_events for details of the key event type and the event timing.
For example, a key press like this:
Key1: _________/"""""""""""""""\\___________
^ ^--- key released
`------------------- key pressed
|<------>| <-- duration_since_start (50ms)
|<---------------------->| duration_since_start (100ms)
would be described with a sequence of two TimedKeyEvent
s (pseudo-code):
[
{ Key1, 50ms, PRESSED },
{ Key1, 100ms, RELEASED },
]
This is not overly useful in the case of a single key press, but is useful to model multiple concurrent keypresses, while allowing an arbitrary interleaving of key events.
Consider a more complicated timing diagram like this one:
Key1: _________/"""""""""""""""\\_____________
Key2: ____/"""""""""""""""\\__________________
Key3: ______/"""""""""""""""\\________________
Key4: _____________/"""""""""""""""\\_________
Key5: ________________ __/""""""\\____________
Key6: ________/""""""\\_______________________
It then becomes obvious how modeling individual events allows us to express this interaction.
Furthermore anchoring duration_since_start
to the beginning of the key sequence (instead of,
for example, specifying the duration of each key press) gives a common time reference and makes
it fairly easy to express the intended key interaction in terms of a TimedKeyEvent
sequence.
Fields§
§key: Key
The input::Key which changed state.
duration_since_start: Duration
The duration of time, relative to the start of the key event sequence that this TimedKeyEvent
is part of, at which this event happened at.
event_type: KeyEventType
The type of state change that happened to key
. Was it pressed, released or something
else.
Implementations§
source§impl TimedKeyEvent
impl TimedKeyEvent
sourcepub fn new(
key: Key,
type_: KeyEventType,
duration_since_start: Duration
) -> Self
pub fn new( key: Key, type_: KeyEventType, duration_since_start: Duration ) -> Self
Creates a new TimedKeyEvent to inject into the input pipeline. key
is
the key to be pressed (using Fuchsia HID-like encoding), type_
is the
event type (Pressed, or Released etc), and duration_since_start
is the
duration since the start of the entire event sequence that the key event
should be scheduled at.
sourcepub fn vec<'de, D>(deserializer: D) -> Result<Vec<TimedKeyEvent>, D::Error>where
D: Deserializer<'de>,
pub fn vec<'de, D>(deserializer: D) -> Result<Vec<TimedKeyEvent>, D::Error>where
D: Deserializer<'de>,
Deserializes a vector of TimedKeyEvent
.
A custom deserializer is used because Vec<_> does not work
with serde, and the TimedKeyEvent has constituents that don’t
have a derived serde representation.
See: https://github.com/serde-rs/serde/issues/723#issuecomment-382501277
Trait Implementations§
source§impl Clone for TimedKeyEvent
impl Clone for TimedKeyEvent
source§fn clone(&self) -> TimedKeyEvent
fn clone(&self) -> TimedKeyEvent
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for TimedKeyEvent
impl Debug for TimedKeyEvent
source§impl PartialEq for TimedKeyEvent
impl PartialEq for TimedKeyEvent
source§fn eq(&self, other: &TimedKeyEvent) -> bool
fn eq(&self, other: &TimedKeyEvent) -> bool
self
and other
values to be equal, and is used
by ==
.