From 38c66803774854cfa8c7f4539480e9e5039ab6de Mon Sep 17 00:00:00 2001 From: tcmal Date: Sun, 25 Aug 2024 17:44:22 +0100 Subject: fix(input): duplicate keyboardevents causing problems --- stockton-input-codegen/src/lib.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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, + is_down: ::std::collections::BTreeMap, just_hot: [bool; #buttons_len] } impl #ident { pub fn new(actions: ::std::collections::BTreeMap) -> 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 { -- cgit v1.2.3