pub struct KeyState { /* private fields */ }Expand description
Tracks which keys are currently held down.
Feed it every KeyEvent (or Event) you receive and query
is_held each frame for held-key movement. A key is
considered held from its first KeyEventKind::Press until a matching
KeyEventKind::Release.
Held keys are keyed by (KeyCode, KeyLocation), so a held Numpad8 and a held digit-row 8 are
tracked separately: is_held takes the pair, and held yields
it.
This is only useful on backends that emit release events (winit, or a
terminal with the kitty keyboard protocol). On press-only backends a key
never leaves the held set on its own, so call clear at a
suitable boundary (e.g. once per turn) if you rely on it there.
Implementations§
Source§impl KeyState
impl KeyState
Sourcepub fn apply_event(&mut self, event: &Event)
pub fn apply_event(&mut self, event: &Event)
Updates the held set from an Event, ignoring non-key events.
Sourcepub fn is_held(&self, code: KeyCode, location: KeyLocation) -> bool
pub fn is_held(&self, code: KeyCode, location: KeyLocation) -> bool
Returns true if code at location is currently held.
Sourcepub fn held(&self) -> impl Iterator<Item = (KeyCode, KeyLocation)> + '_
pub fn held(&self) -> impl Iterator<Item = (KeyCode, KeyLocation)> + '_
Iterates the currently held (code, location) pairs, in first-pressed order.