diff options
| author | HampusM <hampus@hampusmat.com> | 2025-11-02 17:30:07 +0100 |
|---|---|---|
| committer | HampusM <hampus@hampusmat.com> | 2025-11-02 17:30:07 +0100 |
| commit | 56dea9f5e8c293bfdfa350f48669e14a5dd4499d (patch) | |
| tree | 5392979e0e307259b37ffac87e862281042709b6 /engine/src/windowing/keyboard.rs | |
| parent | a63e128d1cb1429fecf3756da4f63925b0333382 (diff) | |
Diffstat (limited to 'engine/src/windowing/keyboard.rs')
| -rw-r--r-- | engine/src/windowing/keyboard.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/engine/src/windowing/keyboard.rs b/engine/src/windowing/keyboard.rs index e4fffe5..a1c3e22 100644 --- a/engine/src/windowing/keyboard.rs +++ b/engine/src/windowing/keyboard.rs @@ -10,6 +10,34 @@ pub struct Keyboard impl Keyboard { + /// Returns whether the given key was just pressed this frame. This function will + /// return `false` if the key was also pressed the previous frame. + pub fn just_pressed(&self, key: Key) -> bool + { + self.get_key_state(key) == KeyState::Pressed + && self.get_prev_key_state(key) == KeyState::Released + } + + /// Returns whether the given key was just released this frame. This function will + /// return `false` if the key was also released the previous frame. + pub fn just_released(&self, key: Key) -> bool + { + self.get_key_state(key) == KeyState::Released + && self.get_prev_key_state(key) == KeyState::Pressed + } + + /// Returns whether the given key is currently pressed. + pub fn pressed(&self, key: Key) -> bool + { + self.get_key_state(key) == KeyState::Pressed + } + + /// Returns whether the given key is currently released. + pub fn released(&self, key: Key) -> bool + { + self.get_key_state(key) == KeyState::Released + } + #[must_use] pub fn get_key_state(&self, key: Key) -> KeyState { |
