Keys

Struct Keys 

Source
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>
where K: Copy + Eq + Hash, I: Copy + Ord + Add<Duration, Output = I> + AddAssign<Duration> + Sub<Output = Duration>,

Source

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.

Source

pub fn on_key_press(&mut self, now: I, key: K)

This method is to be invoked on every key press received.

Source

pub fn on_key_release(&mut self, now: I, key: K)

This method is to be invoked on every key release received.

Source

pub fn tick<F, C>(&mut self, now: I, handler: F) -> (C, Option<I>)
where F: FnMut(&K, &mut KeyRepeat) -> C, C: Default + BitOrAssign,

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).

Source

pub fn clear(&mut self)

Clear all pressed keys, i.e., marking them all as released.

Trait Implementations§

Source§

impl<K: Debug, I: Debug> Debug for Keys<K, I>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<K, I> Freeze for Keys<K, I>

§

impl<K, I> RefUnwindSafe for Keys<K, I>

§

impl<K, I> Send for Keys<K, I>
where K: Send, I: Send,

§

impl<K, I> Sync for Keys<K, I>
where K: Sync, I: Sync,

§

impl<K, I> Unpin for Keys<K, I>
where K: Unpin, I: Unpin,

§

impl<K, I> UnwindSafe for Keys<K, I>
where K: UnwindSafe, I: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.