pub struct Input { /* private fields */ }Expand description
Input state manager
Tracks keyboard and mouse states using a 256-bit bitmask array. Provides frame-accurate detection for pressed, just pressed, and just released states.
§State Storage
- Keys: bits 0-127
- Mouse buttons: bits 128-255
§Frame Detection
is_*_pressed: Currently held downjust_*_pressed: Pressed this frame (not held last frame)just_*_released: Released this frame (was held last frame)
§Example
// Direct key/button queries
if input.is_key_pressed(KeyCode::W) { ... }
if input.just_button_pressed(MouseButton::Left) { ... }
// Action-based queries (recommended)
if input.is_action_pressed("MoveForward") { ... }
if input.just_action_pressed("Fire") { ... }Implementations§
Source§impl Input
impl Input
Sourcepub fn is_key_pressed(&self, key: KeyCode) -> bool
pub fn is_key_pressed(&self, key: KeyCode) -> bool
Returns true if the key is currently held down
Sourcepub fn just_key_pressed(&self, key: KeyCode) -> bool
pub fn just_key_pressed(&self, key: KeyCode) -> bool
Returns true if the key was pressed this frame
Only returns true on the first frame the key is pressed.
Sourcepub fn just_key_released(&self, key: KeyCode) -> bool
pub fn just_key_released(&self, key: KeyCode) -> bool
Returns true if the key was released this frame
Only returns true on the first frame the key is released.
Returns true if the mouse button is currently held down
Returns true if the mouse button was pressed this frame
Returns true if the mouse button was released this frame
Sourcepub fn is_action_pressed(&self, action: &str) -> bool
pub fn is_action_pressed(&self, action: &str) -> bool
Returns true if any input bound to the action is currently held
Checks all input sources registered for the action. For chords, both keys must be held.
Sourcepub fn just_action_pressed(&self, action: &str) -> bool
pub fn just_action_pressed(&self, action: &str) -> bool
Returns true if any input bound to the action was triggered this frame
For single keys/buttons: true on the frame they’re pressed. For chords: true when the final key/button completes the chord.
Sourcepub fn just_action_released(&self, action: &str) -> bool
pub fn just_action_released(&self, action: &str) -> bool
Returns true if any input bound to the action was released this frame
For chords: true when the non-modifier key/button is released while the modifier is still held.
Sourcepub fn add_binding(&mut self, action: &str, source: InputSource)
pub fn add_binding(&mut self, action: &str, source: InputSource)
Registers an input source for an action
Multiple sources can be bound to the same action. The action triggers if any of its sources are activated.
§Example
// Multiple keys for the same action
input.add_binding("MoveForward", InputSource::Key(KeyCode::W));
input.add_binding("MoveForward", InputSource::Key(KeyCode::Up));
// Key + mouse chord
input.add_binding("SpecialAttack", InputSource::MouseChord(KeyCode::LShift, MouseButton::Left));Trait Implementations§
Auto Trait Implementations§
impl Freeze for Input
impl RefUnwindSafe for Input
impl Send for Input
impl Sync for Input
impl Unpin for Input
impl UnwindSafe for Input
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.