pub struct KeyboardManager { /* private fields */ }Expand description
Tracks keyboard key state and edge transitions across frames.
Call update each frame with a keyboard provider, then query
edge methods such as is_key_pressed.
§Examples
use cotis_interactivity::keyboard::KeyboardManager;
use cotis_utils::interactivity::keyboard::KeyboardKey;
// let mut keyboard = KeyboardManager::new();
// keyboard.update(app.render_borrow());
// if keyboard.is_key_pressed(KeyboardKey::KeyEscape) { ... }Implementations§
Source§impl KeyboardManager
impl KeyboardManager
Sourcepub fn new() -> KeyboardManager
pub fn new() -> KeyboardManager
Creates an empty keyboard manager.
Sourcepub fn update(&mut self, provider: &dyn SimpleKeyboardProvider)
pub fn update(&mut self, provider: &dyn SimpleKeyboardProvider)
Syncs tracked keys from provider’s current pressed-key set.
Keys that appear in the provider for the first time produce a rising edge on the frame they are first seen.
Sourcepub fn is_key_pressed(&self, key: KeyboardKey) -> bool
pub fn is_key_pressed(&self, key: KeyboardKey) -> bool
Returns true on the frame a key is first pressed (rising edge).
Sourcepub fn is_key_pressed_repeat(&self, key: KeyboardKey) -> bool
pub fn is_key_pressed_repeat(&self, key: KeyboardKey) -> bool
Returns true when a key has been held for two or more consecutive frames.
§Note
This is not operating-system key-repeat timing. It detects sustained
holds via an internal two-frame threshold (is_on_long).
Sourcepub fn is_key_down(&self, key: KeyboardKey) -> bool
pub fn is_key_down(&self, key: KeyboardKey) -> bool
Returns true while a key is currently held down.
Sourcepub fn is_key_up(&self, key: KeyboardKey) -> bool
pub fn is_key_up(&self, key: KeyboardKey) -> bool
Returns true while a key is not held down.
Sourcepub fn is_key_released(&self, key: KeyboardKey) -> bool
pub fn is_key_released(&self, key: KeyboardKey) -> bool
Returns true on the frame a key is released (falling edge).
Sourcepub fn get_key_pressed(&mut self) -> Option<KeyboardKey>
pub fn get_key_pressed(&mut self) -> Option<KeyboardKey>
Returns the most recently pressed key according to provider iteration order.
The return value reflects the last key in get_pressed_keys() from the
most recent update call.