@@ -245,41 +245,43 @@ func (d *Device) Tick() error {
245
245
}
246
246
247
247
d .founds = d .founds [:0 ]
248
- for _ , xx := range noneToPresse {
249
- kbidx , layer , index := decKey (xx )
250
- x := d .kb [kbidx ].Key (layer , index )
251
- for _ , combo := range d .Combos {
252
- for _ , ckey := range combo [:4 ] {
253
- if keycodeViaToTGK (ckey ) == x {
254
- uniq := true
255
- for _ , f := range d .founds {
256
- if f == ckey {
257
- uniq = false
248
+ if d .combosKey == 0xFFFFFFFF {
249
+ for _ , xx := range noneToPresse {
250
+ kbidx , layer , index := decKey (xx )
251
+ x := d .kb [kbidx ].Key (layer , index )
252
+ for _ , combo := range d .Combos {
253
+ for _ , ckey := range combo [:4 ] {
254
+ if keycodeViaToTGK (ckey ) == x {
255
+ uniq := true
256
+ for _ , f := range d .founds {
257
+ if f == ckey {
258
+ uniq = false
259
+ }
258
260
}
261
+ if uniq {
262
+ d .founds = append (d .founds , ckey )
263
+ }
264
+ if d .combosTimer .IsZero () {
265
+ d .combosTimer = time .Now ().Add (48 * time .Millisecond )
266
+ }
267
+ d .combosPressed [xx ] = struct {}{}
259
268
}
260
- if uniq {
261
- d .founds = append (d .founds , ckey )
262
- }
263
- if d .combosTimer .IsZero () {
264
- d .combosTimer = time .Now ().Add (48 * time .Millisecond )
265
- }
266
- d .combosPressed [xx ] = struct {}{}
267
269
}
268
270
}
269
271
}
270
- }
271
- if len (d .founds ) == len (noneToPresse ) {
272
- // Remove the keys pressed before the Combos are completed.
273
- noneToPresse = noneToPresse [:0 ]
274
- } else {
275
- // Cancel the Combos waiting state if a key unrelated to Combos is pressed.
276
- d .combosTimer = time.Time {}
277
- for xx := range d .combosPressed {
278
- noneToPresse = append (noneToPresse , xx )
279
- delete (d .combosPressed , xx )
272
+ if len (d .founds ) == len (noneToPresse ) {
273
+ // Remove the keys pressed before the Combos are completed.
274
+ noneToPresse = noneToPresse [:0 ]
275
+ } else {
276
+ // Cancel the Combos waiting state if a key unrelated to Combos is pressed.
277
+ d .combosTimer = time.Time {}
278
+ for xx := range d .combosPressed {
279
+ noneToPresse = append (noneToPresse , xx )
280
+ delete (d .combosPressed , xx )
281
+ }
282
+ pressToRelease = append (d .combosReleased , pressToRelease ... )
283
+ d .combosReleased = d .combosReleased [:0 ]
280
284
}
281
- pressToRelease = append (d .combosReleased , pressToRelease ... )
282
- d .combosReleased = d .combosReleased [:0 ]
283
285
}
284
286
285
287
if ! d .combosTimer .IsZero () {
@@ -321,9 +323,6 @@ func (d *Device) Tick() error {
321
323
if matched {
322
324
noneToPresse = append (noneToPresse , d .combosKey )
323
325
324
- for k := range d .combosPressed {
325
- delete (d .combosPressed , k )
326
- }
327
326
d .combosReleased = d .combosReleased [:0 ]
328
327
} else {
329
328
for k := range d .combosPressed {
@@ -399,8 +398,13 @@ func (d *Device) Tick() error {
399
398
}
400
399
}
401
400
402
- if len (pressToRelease ) > 0 && d .combosKey != 0xFFFFFFFF {
403
- // For simplicity, the release timing is set to when any key is released.
401
+ for _ , xx := range pressToRelease {
402
+ if _ , ok := d .combosPressed [xx ]; ok {
403
+ delete (d .combosPressed , xx )
404
+ }
405
+ }
406
+ if len (pressToRelease ) > 0 && d .combosKey != 0xFFFFFFFF && len (d .combosPressed ) == 0 {
407
+ // Combos are deactivated when the last key that constitutes the combo is released.
404
408
pressToRelease = append (pressToRelease , d .combosKey )
405
409
d .combosKey = 0xFFFFFFFF
406
410
}
0 commit comments