summaryrefslogtreecommitdiff
path: root/src/input.rs
diff options
context:
space:
mode:
authorMica White <botahamec@outlook.com>2026-06-28 11:09:28 -0400
committerMica White <botahamec@outlook.com>2026-06-28 11:09:28 -0400
commit3eb02cbe5b106cd332f25d658430f7e0ae320745 (patch)
tree20153b185b2e7d5c41b2b2d29c6c28bba8bd31b9 /src/input.rs
parentb9570962cfc214bbac0f3fef1e6c1f9848f52658 (diff)
initial commit
Diffstat (limited to 'src/input.rs')
-rw-r--r--src/input.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/input.rs b/src/input.rs
new file mode 100644
index 0000000..c86daf4
--- /dev/null
+++ b/src/input.rs
@@ -0,0 +1,27 @@
+use crossterm::event::KeyCode;
+use rustc_hash::FxHashSet;
+
+#[derive(Debug, Default, Clone)]
+pub struct InputManager {
+ pressed_keys: FxHashSet<KeyCode>,
+}
+
+impl InputManager {
+ pub fn new() -> Self {
+ Self {
+ pressed_keys: FxHashSet::default(),
+ }
+ }
+
+ pub fn press_key(&mut self, key_code: KeyCode) {
+ self.pressed_keys.insert(key_code);
+ }
+
+ pub fn reset_next_frame(&mut self) {
+ self.pressed_keys.clear();
+ }
+
+ pub fn is_key_pressed_this_frame(&self, key_code: KeyCode) -> bool {
+ self.pressed_keys.contains(&key_code)
+ }
+}