summaryrefslogtreecommitdiff
path: root/engine/src/windowing
diff options
context:
space:
mode:
Diffstat (limited to 'engine/src/windowing')
-rw-r--r--engine/src/windowing/keyboard.rs28
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
{