pub struct Keys<K, I = Instant> { /* private fields */ }Expand description
A type tracking key states and implementing key auto-repeats at a given interval after an initial “timeout”.
In general, interaction with this object follows the pattern of
feeding key presses and releases as delivered by “the system” via
the on_key_press and
on_key_release methods. After that you
would tick the object, which will invoke a handler
function for all the key presses and repeats accumulated since the
last time it was invoked.
For a complete and runnable example illustrating usage please refer
to winit-phys-events.rs.
Implementations§
Source§impl<K, I> Keys<K, I>
impl<K, I> Keys<K, I>
Sourcepub fn new(timeout: Duration, interval: Duration) -> Self
pub fn new(timeout: Duration, interval: Duration) -> Self
Create a new Keys object using timeout as the initial
timeout after which pressed keys transition into auto-repeat mode
at interval interval.
Sourcepub fn on_key_press(&mut self, now: I, key: K)
pub fn on_key_press(&mut self, now: I, key: K)
This method is to be invoked on every key press received.
Sourcepub fn on_key_release(&mut self, now: I, key: K)
pub fn on_key_release(&mut self, now: I, key: K)
This method is to be invoked on every key release received.
Sourcepub fn tick<F, C>(&mut self, now: I, handler: F) -> (C, Option<I>)
pub fn tick<F, C>(&mut self, now: I, handler: F) -> (C, Option<I>)
Handle a “tick”, i.e., evaluate currently pressed keys based on
the provided time, invoking handler for each overdue repeat
event.
handler can change the key’s KeyRepeat state (key repetition
is enabled by default).
Furthermore, handler may return any kind of state that can be
bitwise ORed, allowing to communicate an abstract notion of
“changes triggered” to callers. In addition, the instant at which
the next “tick” is likely to occur (and, hence, this function
should be invoked) is returned as well (if any).