Skip to content

Commit 64eaa97

Browse files
authored
Fix the press order when cancelling Combos (#64)
1 parent ea24640 commit 64eaa97

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

keyboard.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,18 @@ func (d *Device) Tick() error {
284284
noneToPress = noneToPress[:0]
285285
} else {
286286
// Cancel the Combos waiting state if a key unrelated to Combos is pressed.
287+
// Sort `d.combosPressed` so that the ones pressed earlier are triggered first.
287288
d.combosTimer = time.Time{}
289+
ofs := len(noneToPress)
290+
noneToPress = d.noneToPressBuf[:ofs+len(d.combosPressed)]
291+
for i := range noneToPress[:ofs] {
292+
noneToPress[len(noneToPress)-1-i] = noneToPress[ofs-1-i]
293+
}
294+
idx := 0
288295
for xx := range d.combosPressed {
289-
noneToPress = append(noneToPress, xx)
296+
noneToPress[idx] = xx
290297
delete(d.combosPressed, xx)
298+
idx++
291299
}
292300
pressToRelease = append(d.combosReleased, pressToRelease...)
293301
d.combosReleased = d.combosReleased[:0]

0 commit comments

Comments
 (0)