Skip to content
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

Change the timing for deactivating Combos #56

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 38 additions & 34 deletions keyboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,41 +245,43 @@ func (d *Device) Tick() error {
}

d.founds = d.founds[:0]
for _, xx := range noneToPresse {
kbidx, layer, index := decKey(xx)
x := d.kb[kbidx].Key(layer, index)
for _, combo := range d.Combos {
for _, ckey := range combo[:4] {
if keycodeViaToTGK(ckey) == x {
uniq := true
for _, f := range d.founds {
if f == ckey {
uniq = false
if d.combosKey == 0xFFFFFFFF {
for _, xx := range noneToPresse {
kbidx, layer, index := decKey(xx)
x := d.kb[kbidx].Key(layer, index)
for _, combo := range d.Combos {
for _, ckey := range combo[:4] {
if keycodeViaToTGK(ckey) == x {
uniq := true
for _, f := range d.founds {
if f == ckey {
uniq = false
}
}
if uniq {
d.founds = append(d.founds, ckey)
}
if d.combosTimer.IsZero() {
d.combosTimer = time.Now().Add(48 * time.Millisecond)
}
d.combosPressed[xx] = struct{}{}
}
if uniq {
d.founds = append(d.founds, ckey)
}
if d.combosTimer.IsZero() {
d.combosTimer = time.Now().Add(48 * time.Millisecond)
}
d.combosPressed[xx] = struct{}{}
}
}
}
}
if len(d.founds) == len(noneToPresse) {
// Remove the keys pressed before the Combos are completed.
noneToPresse = noneToPresse[:0]
} else {
// Cancel the Combos waiting state if a key unrelated to Combos is pressed.
d.combosTimer = time.Time{}
for xx := range d.combosPressed {
noneToPresse = append(noneToPresse, xx)
delete(d.combosPressed, xx)
if len(d.founds) == len(noneToPresse) {
// Remove the keys pressed before the Combos are completed.
noneToPresse = noneToPresse[:0]
} else {
// Cancel the Combos waiting state if a key unrelated to Combos is pressed.
d.combosTimer = time.Time{}
for xx := range d.combosPressed {
noneToPresse = append(noneToPresse, xx)
delete(d.combosPressed, xx)
}
pressToRelease = append(d.combosReleased, pressToRelease...)
d.combosReleased = d.combosReleased[:0]
}
pressToRelease = append(d.combosReleased, pressToRelease...)
d.combosReleased = d.combosReleased[:0]
}

if !d.combosTimer.IsZero() {
Expand Down Expand Up @@ -321,9 +323,6 @@ func (d *Device) Tick() error {
if matched {
noneToPresse = append(noneToPresse, d.combosKey)

for k := range d.combosPressed {
delete(d.combosPressed, k)
}
d.combosReleased = d.combosReleased[:0]
} else {
for k := range d.combosPressed {
Expand Down Expand Up @@ -399,8 +398,13 @@ func (d *Device) Tick() error {
}
}

if len(pressToRelease) > 0 && d.combosKey != 0xFFFFFFFF {
// For simplicity, the release timing is set to when any key is released.
for _, xx := range pressToRelease {
if _, ok := d.combosPressed[xx]; ok {
delete(d.combosPressed, xx)
}
}
if len(pressToRelease) > 0 && d.combosKey != 0xFFFFFFFF && len(d.combosPressed) == 0 {
// Combos are deactivated when the last key that constitutes the combo is released.
pressToRelease = append(pressToRelease, d.combosKey)
d.combosKey = 0xFFFFFFFF
}
Expand Down
Loading