Skip to content

Commit

Permalink
Fix the press order when cancelling Combos (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
sago35 authored Dec 24, 2024
1 parent ea24640 commit 64eaa97
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion keyboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,18 @@ func (d *Device) Tick() error {
noneToPress = noneToPress[:0]
} else {
// Cancel the Combos waiting state if a key unrelated to Combos is pressed.
// Sort `d.combosPressed` so that the ones pressed earlier are triggered first.
d.combosTimer = time.Time{}
ofs := len(noneToPress)
noneToPress = d.noneToPressBuf[:ofs+len(d.combosPressed)]
for i := range noneToPress[:ofs] {
noneToPress[len(noneToPress)-1-i] = noneToPress[ofs-1-i]
}
idx := 0
for xx := range d.combosPressed {
noneToPress = append(noneToPress, xx)
noneToPress[idx] = xx
delete(d.combosPressed, xx)
idx++
}
pressToRelease = append(d.combosReleased, pressToRelease...)
d.combosReleased = d.combosReleased[:0]
Expand Down

0 comments on commit 64eaa97

Please sign in to comment.