diff options
author | tcmal <me@aria.rip> | 2024-08-25 17:44:22 +0100 |
---|---|---|
committer | tcmal <me@aria.rip> | 2024-08-25 17:44:22 +0100 |
commit | 38c66803774854cfa8c7f4539480e9e5039ab6de (patch) | |
tree | 6f2d5a362a910d219f609b91c90f1df4767783d5 | |
parent | fff14bd55be2f1c98a03fc4e68bc08f065a3d4ca (diff) |
fix(input): duplicate keyboardevents causing problems
-rw-r--r-- | stockton-input-codegen/src/lib.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/stockton-input-codegen/src/lib.rs b/stockton-input-codegen/src/lib.rs index d3ee525..ce8dfc8 100644 --- a/stockton-input-codegen/src/lib.rs +++ b/stockton-input-codegen/src/lib.rs @@ -176,14 +176,21 @@ fn gen_manager_struct( struct #ident { inputs: #struct_ident, actions: ::std::collections::BTreeMap<u32, (#fields_enum_ident, ::stockton_input::InputMutation)>, + is_down: ::std::collections::BTreeMap<u32, bool>, just_hot: [bool; #buttons_len] } impl #ident { pub fn new(actions: ::std::collections::BTreeMap<u32, (#fields_enum_ident, ::stockton_input::InputMutation)>) -> Self { + let mut is_down = ::std::collections::BTreeMap::new(); + for (k,_) in actions.iter() { + is_down.insert(*k, false); + } + #ident { inputs: Default::default(), actions, + is_down, just_hot: [#(#jh_falses),*] } } @@ -257,6 +264,13 @@ fn gen_trait_impl( let mutation = self.actions.get(&action.keycode()); if let Some((field, mutation)) = mutation { + if *self.is_down.get(&action.keycode()).unwrap() == action.is_down() { + // Duplicate event + continue; + } + + self.is_down.insert(action.keycode(), action.is_down()); + use ::stockton_input::InputMutation; let mut val = match mutation { |