Repository: HaoboGu/rmk (language: rust)

Issue:
Odd behaviour with tap-hold keys
I've been running into some rather odd behaviour with the tap-hold keys. Sometimes my keyboard seems to just get stuck in the layer that it's meant to switch to when holding, it doesn't always revert back to the original layer once I release the key. This also seems to introduce some other wacky behaviour, such as some keys just not working entirely after typing for a little when it gets stuck, and there's a condition where it seems to just continually spam a key since it seems to register it being pressed but never released.
Unsure if this is an issue in the code, or if maybe I'm running into some memory issues? I'm certain this would have been seen by someone else if it was a problem with the code, so just curious if this is a known problem or if there's something else going on here.


Discussion / hints:
Do all those odd behaviors happen only for tap-hold keys?

Fix patch:
diff --git a/rmk/src/keyboard.rs b/rmk/src/keyboard.rs
index 088d6091..f8b95725 100644
--- a/rmk/src/keyboard.rs
+++ b/rmk/src/keyboard.rs
@@ -390,24 +390,18 @@ impl<'a, const ROW: usize, const COL: usize, const NUM_LAYER: usize>
 
                         // The actual processing is postponed because we cannot do recursion on async function without alloc
                         // After current key processing is done, we can process events in queue until the queue is empty
-                        if self.unprocessed_events.push(key_event).is_err() {
+                        if self.unprocessed_events.push(e).is_err() {
                             warn!("unprocessed event queue is full, dropping event");
                         }
                     }
                 }
             }
         } else {
-            if let Some(start) = self.timer[col][row] {
-                let elapsed = start.elapsed().as_millis();
-                if elapsed > 200 {
-                    // Release hold action, then clear timer
-                    debug!(
-                        "HOLD releasing: {}, {}, time elapsed: {}ms",
-                        hold_action, key_event.pressed, elapsed
-                    );
-                    self.process_key_action_normal(hold_action, key_event).await;
-                    self.timer[col][row] = None;
-                }
+            if let Some(_) = self.timer[col][row] {
+                // Release hold action, then clear timer
+                debug!("HOLD releasing: {}, {}", hold_action, key_event.pressed);
+                self.process_key_action_normal(hold_action, key_event).await;
+                self.timer[col][row] = None;
             }
         }
     }


Test patch: