Skip to main content

InputState

Struct InputState 

Source
pub struct InputState { /* private fields */ }
Expand description

Input state tracker for keyboard, mouse, and other input devices.

This struct tracks the current state of all input devices and provides convenient methods for querying input state. It distinguishes between keys/buttons that are currently held, just pressed this frame, or just released this frame.

Implementations§

Source§

impl InputState

Source

pub fn new() -> Self

Create a new input state tracker.

Source

pub fn handle_events(&mut self, events: &mut EventBatch)

Process events from the event batch.

This should be called each frame before querying input state.

Source

pub fn end_frame(&mut self)

Clear per-frame state. Call this at the end of each frame.

Source

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

Check if a key is currently pressed (held down).

Source

pub fn is_key_just_pressed(&self, key: KeyCode) -> bool

Check if a key was just pressed this frame.

Source

pub fn is_key_just_released(&self, key: KeyCode) -> bool

Check if a key was just released this frame.

Source

pub fn is_any_key_pressed(&self, keys: &[KeyCode]) -> bool

Check if any of the given keys are pressed.

Source

pub fn are_all_keys_pressed(&self, keys: &[KeyCode]) -> bool

Check if all of the given keys are pressed.

Source

pub fn modifiers(&self) -> Modifiers

Get the current modifier key state.

Source

pub fn is_shift_pressed(&self) -> bool

Check if Shift is held.

Source

pub fn is_ctrl_pressed(&self) -> bool

Check if Ctrl (or Cmd on macOS) is held.

Source

pub fn is_alt_pressed(&self) -> bool

Check if Alt (or Option on macOS) is held.

Source

pub fn is_meta_pressed(&self) -> bool

Check if Meta (Windows key or Cmd on macOS) is held.

Source

pub fn text_input(&self) -> &str

Get text input received this frame.

Source

pub fn pressed_keys(&self) -> impl Iterator<Item = &KeyCode>

Get all keys currently pressed.

Source

pub fn is_mouse_button_pressed(&self, button: MouseButton) -> bool

Check if a mouse button is currently pressed.

Source

pub fn is_mouse_button_just_pressed(&self, button: MouseButton) -> bool

Check if a mouse button was just pressed this frame.

Source

pub fn is_mouse_button_just_released(&self, button: MouseButton) -> bool

Check if a mouse button was just released this frame.

Source

pub fn is_left_mouse_pressed(&self) -> bool

Check if left mouse button is pressed.

Source

pub fn is_left_mouse_just_pressed(&self) -> bool

Check if left mouse button was just pressed.

Source

pub fn is_right_mouse_pressed(&self) -> bool

Check if right mouse button is pressed.

Source

pub fn is_right_mouse_just_pressed(&self) -> bool

Check if right mouse button was just pressed.

Source

pub fn is_middle_mouse_pressed(&self) -> bool

Check if middle mouse button is pressed.

Source

pub fn mouse_position(&self) -> Vec2

Get the current mouse position in window coordinates.

Source

pub fn mouse_delta(&self) -> Vec2

Get the mouse movement delta since last frame.

Source

pub fn scroll_delta(&self) -> Vec2

Get the scroll wheel delta since last frame.

Positive Y = scroll up, Negative Y = scroll down.

Source

pub fn is_mouse_in_window(&self) -> bool

Check if the mouse cursor is inside the window.

Source

pub fn horizontal_axis(&self) -> f32

Get horizontal input axis (-1, 0, or 1) from arrow keys or WASD.

Source

pub fn vertical_axis(&self) -> f32

Get vertical input axis (-1, 0, or 1) from arrow keys or WASD.

Source

pub fn movement_direction(&self) -> Vec2

Get movement direction as a normalized vector.

Source

pub fn reset(&mut self)

Reset all input state.

Trait Implementations§

Source§

impl Debug for InputState

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for InputState

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more