pub struct KeyState { /* private fields */ }
Expand description
Tracks the current state of all the keyboard keys.
This is repetitive code, so perhaps better handle it here. You can feed the keyboard events into its KeyState::update method.
KeyState keeps track of the ordering the keys were pressed, and you can call KeyState::get_ordered_keys to get a sequence of currently pressed keys, in the order they were pressed. This is useful for emitting keyboard events that must happen in a very particular ordering.
Implementations§
Source§impl KeyState
impl KeyState
Sourcepub fn update(&mut self, event: KeyEventType, key: Key)
pub fn update(&mut self, event: KeyEventType, key: Key)
Updates the key tracking state with the given key event pair.
Sourcepub fn is_pressed(&self, key: &Key) -> bool
pub fn is_pressed(&self, key: &Key) -> bool
Returns true if key
is noted as pressed.
Sourcepub fn pressed_any(&self, keys: &[Key]) -> bool
pub fn pressed_any(&self, keys: &[Key]) -> bool
Returns true
if at least one key from keys
is pressed.
Sourcepub fn pressed_all(&self, keys: &[Key]) -> bool
pub fn pressed_all(&self, keys: &[Key]) -> bool
Returns true
if all keys from keys
are pressed.
Sourcepub fn get_ordered_keys(&self) -> Vec<Key>
pub fn get_ordered_keys(&self) -> Vec<Key>
Gets the list of all currently pressed keys, in the order they were pressed.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for KeyState
impl RefUnwindSafe for KeyState
impl Send for KeyState
impl Sync for KeyState
impl Unpin for KeyState
impl UnwindSafe for KeyState
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
Mutably borrows from an owned value. Read more
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)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)