Skip to main content

KeyboardManager

Struct KeyboardManager 

Source
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

Source

pub fn new() -> KeyboardManager

Creates an empty keyboard manager.

Source

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.

Source

pub fn is_key_pressed(&self, key: KeyboardKey) -> bool

Returns true on the frame a key is first pressed (rising edge).

Source

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

Source

pub fn is_key_down(&self, key: KeyboardKey) -> bool

Returns true while a key is currently held down.

Source

pub fn is_key_up(&self, key: KeyboardKey) -> bool

Returns true while a key is not held down.

Source

pub fn is_key_released(&self, key: KeyboardKey) -> bool

Returns true on the frame a key is released (falling edge).

Source

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.

Trait Implementations§

Source§

impl Default for KeyboardManager

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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.