Skip to main content

InputState

Struct InputState 

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

Zero-allocation Copy polled keyboard, pointer, and scroll input state for games and interactive viewports.

Implementations§

Source§

impl InputState

Per-frame input ingestion and real-time polling helpers for InputState.

Source

pub fn begin_frame(&mut self)

Clears transient per-frame edge states (just_pressed, just_released, deltas) after a frame step.

§Arguments
  • &Self - Mutable input state.
Source

pub fn without_edges(&self) -> Self

Returns a zero-allocation Copy snapshot containing held keys/buttons and axes with all transient edge events cleared.

Used when executing subsequent fixed-timestep substeps so press/release edges are consumed exactly once.

§Arguments
  • &Self - Input state reference.
§Returns
  • Self - Edge-cleared input snapshot preserving held state.
Source

pub fn has_pending_edges(&self) -> bool

Returns true when any transient edge (just_pressed, just_released, pointer/scroll delta) is latched.

§Arguments
  • &Self - Input state reference.
§Returns
  • bool - Whether pending edge events remain unconsumed.
Source

pub fn ingest(&mut self, event: &WindowEvent)

Updates continuous and edge-triggered states from a platform WindowEvent.

§Arguments
  • &Self - Mutable input state.
  • &WindowEvent - Incoming OS or test event.
Source

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

Returns true while key is held down.

§Arguments
  • &Self - Input state reference.
  • KeyCode - Key to query.
§Returns
  • bool - Whether the key is held.
Source

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

Returns true if key transitioned from up to down during the current frame.

§Arguments
  • &Self - Input state reference.
  • KeyCode - Key to query.
§Returns
  • bool - Whether the key was just pressed.
Source

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

Returns true if key transitioned from down to up during the current frame.

§Arguments
  • &Self - Input state reference.
  • KeyCode - Key to query.
§Returns
  • bool - Whether the key was just released.
Source

pub fn is_button_down(&self, button: PointerButton) -> bool

Returns true while pointer button is held down.

§Arguments
  • &Self - Input state reference.
  • PointerButton - Button to query.
§Returns
  • bool - Whether the button is held.
Source

pub fn is_button_just_pressed(&self, button: PointerButton) -> bool

Returns true if pointer button transitioned from up to down during the current frame.

§Arguments
  • &Self - Input state reference.
  • PointerButton - Button to query.
§Returns
  • bool - Whether the button was just pressed.
Source

pub fn is_button_just_released(&self, button: PointerButton) -> bool

Returns true if pointer button transitioned from down to up during the current frame.

§Arguments
  • &Self - Input state reference.
  • PointerButton - Button to query.
§Returns
  • bool - Whether the button was just released.
Source

pub fn axis(&self, negative: KeyCode, positive: KeyCode) -> f32

Computes a normalized -1.0..=1.0 movement axis from negative and positive key bindings.

§Arguments
  • &Self - Input state reference.
  • KeyCode - Negative direction key.
  • KeyCode - Positive direction key.
§Returns
  • f32 - Axis value in {-1.0, 0.0, 1.0}.
Source

pub fn set_virtual_stick(&mut self, dx: f32, dy: f32)

Sets the normalized analog virtual stick vector (dx, dy) for mobile touch joysticks or gamepads.

§Arguments
  • &Self - Mutable input state.
  • f32 - Horizontal axis in [-1.0, 1.0].
  • f32 - Vertical axis in [-1.0, 1.0].
Source

pub fn clear_virtual_stick(&mut self)

Resets the virtual analog stick to neutral (0.0, 0.0).

§Arguments
  • &Self - Mutable input state.
Source§

impl InputState

Source

pub fn get_keys_down(&self) -> KeyBitset

Source

pub fn get_mut_keys_down(&mut self) -> &mut KeyBitset

Source

pub fn set_keys_down(&mut self, val: KeyBitset) -> &mut Self

Source

pub fn get_keys_just_pressed(&self) -> KeyBitset

Source

pub fn get_mut_keys_just_pressed(&mut self) -> &mut KeyBitset

Source

pub fn set_keys_just_pressed(&mut self, val: KeyBitset) -> &mut Self

Source

pub fn get_keys_just_released(&self) -> KeyBitset

Source

pub fn get_mut_keys_just_released(&mut self) -> &mut KeyBitset

Source

pub fn set_keys_just_released(&mut self, val: KeyBitset) -> &mut Self

Source

pub fn get_buttons_down(&self) -> ButtonBitset

Source

pub fn get_mut_buttons_down(&mut self) -> &mut ButtonBitset

Source

pub fn set_buttons_down(&mut self, val: ButtonBitset) -> &mut Self

Source

pub fn get_buttons_just_pressed(&self) -> ButtonBitset

Source

pub fn get_mut_buttons_just_pressed(&mut self) -> &mut ButtonBitset

Source

pub fn set_buttons_just_pressed(&mut self, val: ButtonBitset) -> &mut Self

Source

pub fn get_buttons_just_released(&self) -> ButtonBitset

Source

pub fn get_mut_buttons_just_released(&mut self) -> &mut ButtonBitset

Source

pub fn set_buttons_just_released(&mut self, val: ButtonBitset) -> &mut Self

Source

pub fn get_pointer_position(&self) -> Point

Source

pub fn get_mut_pointer_position(&mut self) -> &mut Point

Source

pub fn set_pointer_position(&mut self, val: Point) -> &mut Self

Source

pub fn get_pointer_delta(&self) -> Point

Source

pub fn get_mut_pointer_delta(&mut self) -> &mut Point

Source

pub fn set_pointer_delta(&mut self, val: Point) -> &mut Self

Source

pub fn get_scroll_delta(&self) -> Point

Source

pub fn get_mut_scroll_delta(&mut self) -> &mut Point

Source

pub fn set_scroll_delta(&mut self, val: Point) -> &mut Self

Source

pub fn get_virtual_axis(&self) -> Point

Source

pub fn get_mut_virtual_axis(&mut self) -> &mut Point

Source

pub fn set_virtual_axis(&mut self, val: Point) -> &mut Self

Source

pub fn get_virtual_fire(&self) -> bool

Source

pub fn get_mut_virtual_fire(&mut self) -> &mut bool

Source

pub fn set_virtual_fire(&mut self, val: bool) -> &mut Self

Source

pub fn get_virtual_dash(&self) -> bool

Source

pub fn get_mut_virtual_dash(&mut self) -> &mut bool

Source

pub fn set_virtual_dash(&mut self, val: bool) -> &mut Self

Source

pub fn get_modifiers(&self) -> Modifiers

Source

pub fn get_mut_modifiers(&mut self) -> &mut Modifiers

Source

pub fn set_modifiers(&mut self, val: Modifiers) -> &mut Self

Source§

impl InputState

Source

pub fn new() -> Self

Trait Implementations§

Source§

impl Clone for InputState

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for InputState

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
Source§

impl PartialEq for InputState

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for InputState

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.