mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
add key repeat filtering
This commit is contained in:
parent
e2a229faf2
commit
761b713d72
1 changed files with 10 additions and 1 deletions
|
|
@ -85,6 +85,13 @@ impl KeyTracker {
|
|||
}
|
||||
}
|
||||
|
||||
/// This is a filter that causes some keys to not be repeatable. In particular,
|
||||
/// we don't want to trigger on the middle menu button or the "action" button if they
|
||||
/// are held down - we jut want to repeat on the left/right/up/down keys
|
||||
pub fn is_repeating(&self, key: KeyPress) -> bool {
|
||||
key == KeyPress::Left || key == KeyPress::Right || key == KeyPress::Up || key == KeyPress::Down
|
||||
}
|
||||
|
||||
/// Processes the current keys pressed, at the current time stamp
|
||||
pub fn update_key_down(&mut self, keys: &[KeyPress], now: u64) {
|
||||
// Handle the case that key A is held down, then key B is held down simultaneously,
|
||||
|
|
@ -126,7 +133,9 @@ impl KeyTracker {
|
|||
for i in 0..self.keys.len() {
|
||||
if now >= self.keys[i].next_repeat_time {
|
||||
let kp = self.keys[i].kp;
|
||||
kps.push(self.map_keypress(kp));
|
||||
if self.is_repeating(kp) {
|
||||
kps.push(self.map_keypress(kp));
|
||||
}
|
||||
// rebasing off of now prevents keys from "lagging on" in case of UI delay
|
||||
self.keys[i].next_repeat_time = now + self.rate_ms as u64;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue