@@ -40,6 +40,8 @@ type Device struct {
40
40
combosKey uint32
41
41
combosFounds []Keycode
42
42
43
+ tapOrHold map [uint32 ]time.Time
44
+
43
45
pressToReleaseBuf []uint32
44
46
noneToPressBuf []uint32
45
47
}
@@ -87,6 +89,8 @@ func New() *Device {
87
89
combosKey : 0xFFFFFFFF ,
88
90
combosFounds : make ([]Keycode , 10 ),
89
91
92
+ tapOrHold : map [uint32 ]time.Time {},
93
+
90
94
pressToReleaseBuf : make ([]uint32 , 0 , 20 ),
91
95
noneToPressBuf : make ([]uint32 , 0 , 20 ),
92
96
}
@@ -344,6 +348,104 @@ func (d *Device) Tick() error {
344
348
}
345
349
}
346
350
351
+ for _ , xx := range noneToPress {
352
+ kbidx , layer , index := decKey (xx )
353
+ x := d .kb [kbidx ].Key (layer , index )
354
+ switch x & keycodes .QuantumMask {
355
+ case keycodes .TypeLxxxT , keycodes .TypeRxxxT :
356
+ d .tapOrHold [xx ] = time .Now ().Add (200 * time .Millisecond )
357
+ }
358
+ }
359
+
360
+ for xx , tt := range d .tapOrHold {
361
+ if tt .IsZero () {
362
+ // hold release
363
+ for _ , yy := range pressToRelease {
364
+ if xx == yy {
365
+ kbidx , layer , index := decKey (xx )
366
+ x := d .kb [kbidx ].Key (layer , index )
367
+ switch x & keycodes .QuantumMask {
368
+ case keycodes .TypeLxxxT :
369
+ if x & keycodes .TypeXCtl > 0 {
370
+ pressToRelease = append (pressToRelease , uint32 (0xFF000000 )| uint32 (keycodes .KeyLeftCtrl ))
371
+ }
372
+ if x & keycodes .TypeXSft > 0 {
373
+ pressToRelease = append (pressToRelease , uint32 (0xFF000000 )| uint32 (keycodes .KeyLeftShift ))
374
+ }
375
+ if x & keycodes .TypeXAlt > 0 {
376
+ pressToRelease = append (pressToRelease , uint32 (0xFF000000 )| uint32 (keycodes .KeyLeftAlt ))
377
+ }
378
+ if x & keycodes .TypeXGui > 0 {
379
+ pressToRelease = append (pressToRelease , uint32 (0xFF000000 )| uint32 (keycodes .KeyWindows ))
380
+ }
381
+ case keycodes .TypeRxxxT :
382
+ if x & keycodes .TypeXCtl > 0 {
383
+ pressToRelease = append (pressToRelease , uint32 (0xFF000000 )| uint32 (keycodes .KeyRightCtrl ))
384
+ }
385
+ if x & keycodes .TypeXSft > 0 {
386
+ pressToRelease = append (pressToRelease , uint32 (0xFF000000 )| uint32 (keycodes .KeyRightShift ))
387
+ }
388
+ if x & keycodes .TypeXAlt > 0 {
389
+ pressToRelease = append (pressToRelease , uint32 (0xFF000000 )| uint32 (keycodes .KeyLeftAlt ))
390
+ }
391
+ if x & keycodes .TypeXGui > 0 {
392
+ pressToRelease = append (pressToRelease , uint32 (0xFF000000 )| uint32 (keycodes .KeyWindows ))
393
+ }
394
+ }
395
+ delete (d .tapOrHold , xx )
396
+ }
397
+ }
398
+ } else if time .Now ().Before (tt ) {
399
+ // tap
400
+ for _ , yy := range pressToRelease {
401
+ if xx == yy {
402
+ kbidx , layer , index := decKey (xx )
403
+ x := d .kb [kbidx ].Key (layer , index )
404
+ switch x & keycodes .QuantumMask {
405
+ case keycodes .TypeLxxxT , keycodes .TypeRxxxT :
406
+ kc := uint32 (0xFF000000 ) | uint32 (keycodeViaToTGK (x & 0x00FF ))
407
+ noneToPress = append (noneToPress , kc )
408
+ pressToRelease = append (pressToRelease , kc )
409
+ }
410
+ delete (d .tapOrHold , xx )
411
+ }
412
+ }
413
+ } else {
414
+ // hold
415
+ kbidx , layer , index := decKey (xx )
416
+ x := d .kb [kbidx ].Key (layer , index )
417
+ switch x & keycodes .QuantumMask {
418
+ case keycodes .TypeLxxxT :
419
+ if x & keycodes .TypeXCtl > 0 {
420
+ noneToPress = append (noneToPress , uint32 (0xFF000000 )| uint32 (keycodes .KeyLeftCtrl ))
421
+ }
422
+ if x & keycodes .TypeXSft > 0 {
423
+ noneToPress = append (noneToPress , uint32 (0xFF000000 )| uint32 (keycodes .KeyLeftShift ))
424
+ }
425
+ if x & keycodes .TypeXAlt > 0 {
426
+ noneToPress = append (noneToPress , uint32 (0xFF000000 )| uint32 (keycodes .KeyLeftAlt ))
427
+ }
428
+ if x & keycodes .TypeXGui > 0 {
429
+ noneToPress = append (noneToPress , uint32 (0xFF000000 )| uint32 (keycodes .KeyWindows ))
430
+ }
431
+ case keycodes .TypeRxxxT :
432
+ if x & keycodes .TypeXCtl > 0 {
433
+ noneToPress = append (noneToPress , uint32 (0xFF000000 )| uint32 (keycodes .KeyRightCtrl ))
434
+ }
435
+ if x & keycodes .TypeXSft > 0 {
436
+ noneToPress = append (noneToPress , uint32 (0xFF000000 )| uint32 (keycodes .KeyRightShift ))
437
+ }
438
+ if x & keycodes .TypeXAlt > 0 {
439
+ noneToPress = append (noneToPress , uint32 (0xFF000000 )| uint32 (keycodes .KeyLeftAlt ))
440
+ }
441
+ if x & keycodes .TypeXGui > 0 {
442
+ noneToPress = append (noneToPress , uint32 (0xFF000000 )| uint32 (keycodes .KeyWindows ))
443
+ }
444
+ }
445
+ d .tapOrHold [xx ] = time.Time {}
446
+ }
447
+ }
448
+
347
449
for _ , xx := range noneToPress {
348
450
kbidx , layer , index := decKey (xx )
349
451
var x Keycode
@@ -362,6 +464,36 @@ func (d *Device) Tick() error {
362
464
} else {
363
465
d .layerStack = append (d .layerStack , d .layer )
364
466
}
467
+ } else if x & keycodes .QuantumMask == keycodes .TypeLxxx && x & keycodes .QuantumTypeMask != 0 {
468
+ // TypeLxxx
469
+ if x & keycodes .TypeXCtl > 0 {
470
+ d .Keyboard .Down (keycodes .KeyLeftCtrl )
471
+ }
472
+ if x & keycodes .TypeXSft > 0 {
473
+ d .Keyboard .Down (keycodes .KeyLeftShift )
474
+ }
475
+ if x & keycodes .TypeXAlt > 0 {
476
+ d .Keyboard .Down (keycodes .KeyLeftAlt )
477
+ }
478
+ if x & keycodes .TypeXGui > 0 {
479
+ d .Keyboard .Down (keycodes .KeyWindows )
480
+ }
481
+ d .Keyboard .Down (k .Keycode (x & 0x00FF | keycodes .TypeNormal ))
482
+ } else if x & keycodes .QuantumMask == keycodes .TypeRxxx && x & keycodes .QuantumTypeMask != 0 {
483
+ // TypeRxxx
484
+ if x & keycodes .TypeXCtl > 0 {
485
+ d .Keyboard .Down (keycodes .KeyRightCtrl )
486
+ }
487
+ if x & keycodes .TypeXSft > 0 {
488
+ d .Keyboard .Down (keycodes .KeyRightShift )
489
+ }
490
+ if x & keycodes .TypeXAlt > 0 {
491
+ d .Keyboard .Down (keycodes .KeyLeftAlt )
492
+ }
493
+ if x & keycodes .TypeXGui > 0 {
494
+ d .Keyboard .Down (keycodes .KeyWindows )
495
+ }
496
+ d .Keyboard .Down (k .Keycode (x & 0x00FF | keycodes .TypeNormal ))
365
497
} else if x == keycodes .KeyRestoreDefaultKeymap {
366
498
// restore default keymap for QMK
367
499
machine .Flash .EraseBlocks (0 , 1 )
@@ -438,6 +570,36 @@ func (d *Device) Tick() error {
438
570
d .layer = d .layerStack [len (d .layerStack )- 1 ]
439
571
}
440
572
}
573
+ } else if x & keycodes .QuantumMask == keycodes .TypeLxxx && x & keycodes .QuantumTypeMask != 0 {
574
+ // TypeLxxx
575
+ if x & keycodes .TypeXCtl > 0 {
576
+ d .Keyboard .Up (keycodes .KeyLeftCtrl )
577
+ }
578
+ if x & keycodes .TypeXSft > 0 {
579
+ d .Keyboard .Up (keycodes .KeyLeftShift )
580
+ }
581
+ if x & keycodes .TypeXAlt > 0 {
582
+ d .Keyboard .Up (keycodes .KeyLeftAlt )
583
+ }
584
+ if x & keycodes .TypeXGui > 0 {
585
+ d .Keyboard .Up (keycodes .KeyWindows )
586
+ }
587
+ d .Keyboard .Up (k .Keycode (x & 0x00FF | keycodes .TypeNormal ))
588
+ } else if x & keycodes .QuantumMask == keycodes .TypeRxxx && x & keycodes .QuantumTypeMask != 0 {
589
+ // TypeRxxx
590
+ if x & keycodes .TypeXCtl > 0 {
591
+ d .Keyboard .Up (keycodes .KeyRightCtrl )
592
+ }
593
+ if x & keycodes .TypeXSft > 0 {
594
+ d .Keyboard .Up (keycodes .KeyRightShift )
595
+ }
596
+ if x & keycodes .TypeXAlt > 0 {
597
+ d .Keyboard .Up (keycodes .KeyLeftAlt )
598
+ }
599
+ if x & keycodes .TypeXGui > 0 {
600
+ d .Keyboard .Up (keycodes .KeyWindows )
601
+ }
602
+ d .Keyboard .Up (k .Keycode (x & 0x00FF | keycodes .TypeNormal ))
441
603
} else if x & 0xF000 == 0xD000 {
442
604
switch x & 0x00FF {
443
605
case 0x01 , 0x02 , 0x04 , 0x08 , 0x10 :
@@ -613,10 +775,20 @@ func (d *Device) KeyVia(layer, kbIndex, index int) Keycode {
613
775
// restore default keymap for QMK
614
776
kc = keycodes .KeyRestoreDefaultKeymap
615
777
default :
616
- if kc & 0xFF00 == keycodes .TypeMacroKey {
778
+ switch kc & keycodes .QuantumMask {
779
+ case keycodes .TypeRxxx , keycodes .TypeLxxxT , keycodes .TypeRxxxT :
617
780
// skip
618
- } else {
619
- kc = kc & 0x0FFF
781
+ default :
782
+ if kc & keycodes .QuantumMask == 0 && kc & keycodes .QuantumTypeMask != 0 {
783
+ // skip (keycodes.TpeLxxx)
784
+ } else {
785
+ switch kc & keycodes .ModKeyMask {
786
+ case keycodes .TypeMacroKey :
787
+ // skip
788
+ default :
789
+ kc = kc & 0x0FFF
790
+ }
791
+ }
620
792
}
621
793
}
622
794
return kc
@@ -680,8 +852,19 @@ func keycodeViaToTGK(key Keycode) Keycode {
680
852
case keycodes .KeyRestoreDefaultKeymap :
681
853
kc = keycodes .KeyRestoreDefaultKeymap
682
854
default :
683
- if key & 0xFF00 == keycodes .TypeMacroKey {
855
+ switch key & keycodes .QuantumMask {
856
+ case keycodes .TypeRxxx , keycodes .TypeLxxxT , keycodes .TypeRxxxT :
684
857
kc = key
858
+ default :
859
+ if key & keycodes .QuantumMask == 0 && key & keycodes .QuantumTypeMask != 0 {
860
+ // keycodes.TpeLxxx
861
+ kc = key
862
+ } else {
863
+ switch key & 0xFF00 {
864
+ case keycodes .TypeMacroKey :
865
+ kc = key
866
+ }
867
+ }
685
868
}
686
869
}
687
870
return kc
0 commit comments