-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Other keys "virtually" being held until TapHold resolves #102
Comments
I did some research... // release already pressed keys with stacked events
let mut filtered_stacked: Stack = ArrayDeque::new();
let mut instant_release: Option<CustomEvent<_>> = None;
for s in self.stacked.iter() {
match s.event {
Event::Release(i, j) => {
// check if the stacked release corresponds to an existing state
let mut custom = CustomEvent::NoEvent;
self.states = self
.states
.iter()
.filter_map(|s| s.release((i, j), &mut custom))
.collect();
if let CustomEvent::Release(_) = custom {
// there is an existing state that can be released by the stacked event
// -> do not put on stack again
instant_release = Some(custom);
break;
} else {
// no existing state can be released by the stacked event
// -> put back on stack
filtered_stacked.push_back(s.clone());
}
}
Event::Press(_, _) => {
// we only care about releases for existing states
// -> put back on stack
filtered_stacked.push_back(s.clone());
}
}
}
// the filtered_stack does not contain the first release event corresponding to an existing state
self.stacked = filtered_stacked;
if let Some(event) = instant_release {
// each tick only generates one event
// -> return early
return event;
}; Also, this requires |
I'll have to read that carefully. I'm on vacation right now. I think you're right on the diagnostic, but I must think on your proposition. |
No hurry. Enjoy your vacation. For when you have time:
pub fn event(&mut self, event: Event) {
let releases_existing_state = match event {
Event::Release(i, j) => self
.states
.iter()
.find(|s| s.release((i, j), &mut CustomEvent::NoEvent).is_none()) // check if it releases an existing state
.is_some(),
Event::Press(_, _) => false,
};
if releases_existing_state {
if let Some(stacked) = self.stacked_no_wait.push_back(event.into()) {
self.unstack(stacked);
}
} else {
if let Some(stacked) = self.stacked.push_back(event.into()) {
self.waiting_into_hold();
self.unstack(stacked);
}
}
}
// unstack events from the "stacked_no_wait" queue
if let Some(s) = self.stacked_no_wait.pop_front() {
return self.unstack(s);
} This way, the search through the Edit: It does fail a test, though. When two hold-taps are consecutively pressed and the first one turns out to be a "hold" and is released before the second one is decided whether it will be a "tap" or a "hold", the "hold" action of the first one will be "held" until the second one is decided. And exactly that "held until the second one is decided" is, what I am trying to avoid for "non-modifier" keys, but which arguably makes sense in the test-case of modifier-keys (the "hold"-action of the hold-tap). |
If one only puts those events into the "no wait" queue that correspond to pub fn event(&mut self, event: Event) {
let releases_existing_state = match event {
Event::Release(i, j) => self
.states
.iter()
.find(|s| {
s.release((i, j), &mut CustomEvent::NoEvent).is_none() // state can be released
&& s.keycode().map_or(false, |k| !k.is_modifier()) // state is a KeyCode that is not a modifier
})
.is_some(),
_ => false,
};
... I'll set up a WIP PR for it once the PR #104 is merged (my sample code is based on the "Queue"-variant). |
This might be related to what @TeXitoi wrote in #25.
I observe multiple key activations in my OS after finishing words, e.g. "timeee ".
After lots of debugging, I think that I can pinpoint the problem:
If a key is pressed and a
TapHold
key pressed afterwards (in my case, the "space" key), but before releasing the previous key, the release of the previous key gets delayed until theTapHold
is resolved.Example (TapHold timeout of 200 ms, OS repeat after 220 ms):
I use a rather low repeat delay in my OS (220 ms, I believe), so if I am a little lazy on the space key, I get the aforementioned multiple quite easily.
The text was updated successfully, but these errors were encountered: