From 56dea9f5e8c293bfdfa350f48669e14a5dd4499d Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 2 Nov 2025 17:30:07 +0100 Subject: feat(engine): add & use Keyboard struct QOL fns --- engine/src/windowing/keyboard.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'engine/src/windowing') 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 { -- cgit v1.2.3-18-g5258