2018-11-06 06:33:42 +01:00
|
|
|
# Tap Dance
|
|
|
|
|
2019-07-13 02:11:36 +02:00
|
|
|
Tap dance is a way to allow a single physical key to work as multiple logical
|
2018-11-06 06:33:42 +01:00
|
|
|
keys / actions without using layers. With basic tap dance, you can trigger these
|
|
|
|
"nested" keys or macros through a series of taps of the physical key within a
|
|
|
|
given timeout.
|
|
|
|
|
|
|
|
The resulting "logical" action works just like any other key - it can be pressed
|
|
|
|
and immediately released, or it can be held. For example, let's take a key
|
|
|
|
`KC.TD(KC.A, KC.B)`. If the tap dance key is tapped and released once quickly,
|
|
|
|
the letter "a" will be sent. If it is tapped and released twice quickly, the
|
|
|
|
letter "b" will be sent. If it is tapped once and held, the letter "a" will be
|
|
|
|
held down until the tap dance key is released. If it is tapped and released once
|
|
|
|
quickly, then tapped and held (both actions within the timeout window), the
|
|
|
|
letter "b" will be held down until the tap dance key is released.
|
|
|
|
|
|
|
|
To use this, you may want to define a `tap_time` value in your keyboard
|
2020-10-21 21:19:42 +02:00
|
|
|
configuration. This is an integer in milliseconds, and defaults to `300`.
|
2022-05-04 19:05:25 +02:00
|
|
|
The timeout is reset after each tap and every tapdance sequence can also define
|
|
|
|
an individual `tap_time`.
|
2018-11-06 06:33:42 +01:00
|
|
|
|
|
|
|
You'll then want to create a sequence of keys using `KC.TD(KC.SOMETHING,
|
|
|
|
KC.SOMETHING_ELSE, MAYBE_THIS_IS_A_MACRO, WHATEVER_YO)`, and place it in your
|
|
|
|
keymap somewhere. The only limits on how many keys can go in the sequence are,
|
2022-05-04 19:05:25 +02:00
|
|
|
theoretically, the amount of RAM your MCU/board has.
|
2018-11-06 06:33:42 +01:00
|
|
|
|
2022-05-04 19:05:25 +02:00
|
|
|
Tap dance supports all `HoldTap` based keys, like mod tap, layer tap, oneshot...
|
|
|
|
it will even honor every option set for those keys.
|
|
|
|
Individual timeouts and prefer hold behavior for every tap in the sequence?
|
|
|
|
Not a problem.
|
2018-11-06 06:33:42 +01:00
|
|
|
|
|
|
|
Here's an example of all this in action:
|
|
|
|
|
|
|
|
```python
|
|
|
|
from kmk.keycodes import KC
|
2022-01-18 06:21:05 +01:00
|
|
|
from kmk.handlers.sequences import send_string
|
|
|
|
from kmk.modules.tapdance import TapDance
|
2018-11-06 06:33:42 +01:00
|
|
|
|
2019-07-25 10:30:55 +02:00
|
|
|
keyboard = KMKKeyboard()
|
2018-11-06 06:33:42 +01:00
|
|
|
|
2022-01-18 06:21:05 +01:00
|
|
|
tapdance = TapDance()
|
|
|
|
tapdance.tap_time = 750
|
|
|
|
keyboard.modules.append(tapdance)
|
2018-11-06 06:33:42 +01:00
|
|
|
|
|
|
|
EXAMPLE_TD = KC.TD(
|
2022-05-04 19:05:25 +02:00
|
|
|
# Tap once for "a"
|
|
|
|
KC.A,
|
|
|
|
# Tap twice for "b", or tap and hold for "left control"
|
|
|
|
KC.MT(KC.B, KC.LCTL, prefer_hold=False),
|
2018-11-06 06:33:42 +01:00
|
|
|
# Tap three times to send a raw string via macro
|
|
|
|
send_string('macros in a tap dance? I think yes'),
|
2022-05-04 19:05:25 +02:00
|
|
|
# Tap four times to toggle layer index 1, tap 3 times and hold for 3s to
|
|
|
|
# momentary toggle layer index 1.
|
|
|
|
KC.TT(1, tap_time=3000),
|
2018-11-06 06:33:42 +01:00
|
|
|
)
|
|
|
|
|
2022-05-04 19:05:25 +02:00
|
|
|
# make the default tap time really short for this tap dance:
|
|
|
|
EXAMPLE_TD2 = KC.TD(KC.A, KC.B, tap_time=80)
|
|
|
|
|
|
|
|
|
2018-11-06 06:33:42 +01:00
|
|
|
keyboard.keymap = [[ ...., EXAMPLE_TD, ....], ....]
|
|
|
|
```
|