fixed combo delay

This commit is contained in:
Daniel Sommer 2022-03-03 03:52:34 +01:00
parent b8e5aa22b5
commit e2b7a71c8e
2 changed files with 8 additions and 4 deletions

View file

@ -16,6 +16,7 @@
], ],
"event": "EV_KEY", "event": "EV_KEY",
"type": "keydown", "type": "keydown",
"delay": 3000,
"command": "notify-send", "command": "notify-send",
"args": [ "args": [
"combo", "combo",

View file

@ -142,7 +142,8 @@ class Keyfilter {
this.currentCombo = { this.currentCombo = {
key: key, key: key,
type: event.type, type: event.type,
start: new Date().getTime(), delay: event.delay,
timestamp: new Date().getTime(),
done: [key], done: [key],
remaining: JSON.parse(JSON.stringify(event.combo)), remaining: JSON.parse(JSON.stringify(event.combo)),
finished: this.hasComboFinished() finished: this.hasComboFinished()
@ -167,6 +168,7 @@ class Keyfilter {
return false; return false;
} }
this.currentCombo.key = parsedEvent.key; this.currentCombo.key = parsedEvent.key;
this.currentCombo.timestamp = new Date().getTime();
this.currentCombo.done.push(parsedEvent.key); this.currentCombo.done.push(parsedEvent.key);
this.currentCombo.remaining.shift(); this.currentCombo.remaining.shift();
this.currentCombo.finished = this.hasComboFinished(); this.currentCombo.finished = this.hasComboFinished();
@ -178,10 +180,11 @@ class Keyfilter {
this.currentCombo.remaining.length === 0; this.currentCombo.remaining.length === 0;
} }
hasComboTimedOut() { hasComboTimedOut() {
return this.currentCombo !== undefined && const result = this.currentCombo !== undefined &&
this.currentCombo.delay !== undefined && this.currentCombo.delay !== undefined &&
this.currentCombo.start !== undefined && this.currentCombo.timestamp !== undefined &&
new Date().getTime() - this.currentCombo.start > this.currentCombo.delay; new Date().getTime() - this.currentCombo.timestamp > this.currentCombo.delay;
return result;
} }
resetCurrentCombo() { resetCurrentCombo() {
this.currentCombo = undefined; this.currentCombo = undefined;