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
impl Eq for TimedKeyEvent
impl StructuralPartialEq for TimedKeyEvent
Auto Trait Implementations§
impl Freeze for TimedKeyEvent
impl RefUnwindSafe for TimedKeyEvent
impl Send for TimedKeyEvent
impl Sync for TimedKeyEvent
impl Unpin for TimedKeyEvent
impl UnwindSafe for TimedKeyEvent
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)