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