<divid="app"><divclass="Layout"data-v-5d98c3a5><!--[--><!--]--><!--[--><spantabindex="-1"data-v-0f60ec36></span><ahref="#VPContent"class="VPSkipLink visually-hidden"data-v-0f60ec36> Skip to content </a><!--]--><!----><headerclass="VPNav"data-v-5d98c3a5data-v-ae24b3ad><divclass="VPNavBar has-sidebar top"data-v-ae24b3addata-v-ccf7ddec><divclass="wrapper"data-v-ccf7ddec><divclass="container"data-v-ccf7ddec><divclass="title"data-v-ccf7ddec><divclass="VPNavBarTitle has-sidebar"data-v-ccf7ddecdata-v-ab179fa1><aclass="title"href="/"data-v-ab179fa1><!--[--><!--]--><!--[--><!--[--><!--[--><imgclass="VPImage dark logo"src="/qmk-logo-dark.svg"altdata-v-8426fc1a><!--]--><!--[--><imgclass="VPImage light logo"src="/qmk-logo-light.svg"altdata-v-8426fc1a><!--]--><!--]--><!--]--><spandata-v-ab179fa1>QMK Firmware</span><!--[--><!--]--></a></div></div><divclass="content"data-v-ccf7ddec><divclass="content-body"data-v-ccf7ddec><!--[--><!--]--><divclass="VPNavBarSearch search"data-v-ccf7ddec><!--[--><!----><divid="local-search"><buttontype="button"class="DocSearch DocSearch-Button"aria-label="Search"><spanclass="DocSearch-Button-Container"><spanclass="vp-icon DocSearch-Search-Icon"></span><spanclass="DocSearch-Button-Placeholder">Search</span></span><spanclass="DocSearch-Button-Keys"><kbdclass="DocSearch-Button-Key"></kbd><kbdclass="DocSearch-Button-Key">K</kbd></span></button></div><!--]--></div><navaria-labelledby="main-nav-aria-label"class="VPNavBarMenu menu"data-v-ccf7ddecdata-v-7f418b0f><spanid="main-nav-aria-label"class="visually-hidden"data-v-7f418b0f>Main Navigation</span><!--[--><!--[--><aclass="VPLink link VPNavBarMenuLink"href="./"tabindex="0"data-v-7f418b0fdata-v-9c663999><!--[--><spandata-v-9c663999>Home</span><!--]--></a><!--]--><!--]--></nav><!----><divclass="VPNavBarAppearance appearance"data-v-ccf7ddecdata-v-e6aabb21><buttonclass="VPSwitch VPSwitchAppearance"type="button"role="switch"title="Switch to dark theme"aria-checked="false"data-v-e6aabb21data-v-d1f28634data-v-1d5665e3><spanclass="check"data-v-1d5665e3><spanclass="icon"data-v-1d5665e3><!--[--><spanclass="vpi-sun sun"data-v-d1f28634></span><spanclass="vpi-moon moon"data-v-d1f28634></span><!--]--></span></span></button></div><divclass="VPSocialLinks VPNavBarSocialLinks social-links"data-v-ccf7ddecdata-v-0394ad82data-v-7bc22406><!--[--><aclass="VPSocialLink no-icon"href="https://reddit.com/r/olkb"aria-labeltarget="_blank"rel="noopener"data-v-7bc22406data-v-eee4e7cb><svgxmlns="http://www.w3.org/2000/svg"viewBox="0 0 50 50"width="50px"height="50px"><pathd="M293C28.0625327.1640633.38281326.54C25.8359384.61718825.3632815.433594256.40625C24.3554698.14062524.08593810.39453124.0312513.03125C19.23437513.17968814.82031314.42187511.2812516.46875C10.21484415.468758.85546914.968757.514.96875C6.08984414.968754.67578115.5117193.5937516.59375C1.42578118.7617191.42578122.2382813.5937524.40625L3.8437524.65625C3.312526.035156327.488281329C333.5273445.56640637.5859389.562540.4375C13.55859443.28906319.007813452545C30.9921884536.44140643.28906340.437540.4375C44.43359437.5859384733.5273444729C4727.48828146.687526.03515646.1562524.65625L46.4062524.40625C48.57421922.23828148.57421918.76171946.4062516.59375C45.32421915.51171943.91015614.9687542.514.96875C41.14453114.9687539.78515615.4687538.7187516.46875C35.19531314.43359430.80078113.19140626.0312513.03125C26.0937510.54687526.3632818.4687526.8757.09375C27.1640636.31640627.5273445.75781327.8755.4375C28.2226565.11718828.5390635295C29.460938529.6835945.12530.031255.40625C30.3789065.687530.7851566.14843831.31256.6875C32.2539067.65234433.6953138.71484436.093758.9375C36.53906311.23828138.574219134113C43.75134610.75468C465.2543.753413C38.605469336.5742194.71093836.093756.96875C34.31256.79687533.5273446.10937532.755.3125C32.3007814.85156331.886719
<spanclass="line"><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">#define</span><spanstyle="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> TAPPING_TERM_PER_KEY</span></span></code></pre></div><p>The <code>TAPPING_TERM</code> time is the maximum time allowed between taps of your Tap Dance key, and is measured in milliseconds. For example, if you used the above <code>#define</code> statement and set up a Tap Dance key that sends <code>Space</code> on single-tap and <code>Enter</code> on double-tap, then this key will send <code>ENT</code> only if you tap this key twice in less than 175ms. If you tap the key, wait more than 175ms, and tap the key again you'll end up sending <code>SPC SPC</code> instead. The <code>TAPPING_TERM_PER_KEY</code> definition is only needed if you control the tapping term through a <ahref="./../tap_hold#tapping_term">custom <code>get_tapping_term</code> function</a>, which may be needed because <code>TAPPING_TERM</code> affects not just tap-dance keys.</p><p>Next, you will want to define some tap-dance keys, which is easiest to do with the <code>TD()</code> macro. That macro takes a number which will later be used as an index into the <code>tap_dance_actions</code> array and turns it into a tap-dance keycode.</p><p>After this, you'll want to use the <code>tap_dance_actions</code> array to specify what actions shall be taken when a tap-dance key is in action. Currently, there are five possible options:</p><ul><li><code>ACTION_TAP_DANCE_DOUBLE(kc1, kc2)</code>: Sends the <code>kc1</code> keycode when tapped once, <code>kc2</code> otherwise. When the key is held, the appropriate keycode is registered: <code>kc1</code> when pressed and held, <code>kc2</code> when tapped once, then pressed and held.</li><li><code>ACTION_TAP_DANCE_LAYER_MOVE(kc, layer)</code>: Sends the <code>kc</code> keycode when tapped once, or moves to <code>layer</code>. (this functions like the <code>TO</code> layer keycode).</li><li><code>ACTION_TAP_DANCE_LAYER_TOGGLE(kc, layer)</code>: Sends the <code>kc</code> keycode when tapped once, or toggles the state of <code>layer</code>. (this functions like the <code>TG</code> layer keycode).</li><li><code>ACTION_TAP_DANCE_FN(fn)</code>: Calls the specified function - defined in the user keymap - with the final tap count of the tap dance action.</li><li><code>ACTION_TAP_DANCE_FN_ADVANCED(on_each_tap_fn, on_dance_finished_fn, on_dance_reset_fn)</code>: Calls the first specified function - defined in the user keymap - on every tap, the second function when the dance action finishes (like the previous option), and the last function when the tap dance action resets.</li><li><code>ACTION_TAP_DANCE_FN_ADVANCED_WITH_RELEASE(on_each_tap_fn, on_each_release_fn, on_dance_finished_fn, on_dance_reset_fn)</code>: This macro is identical to <code>ACTION_TAP_DANCE_FN_ADVANCED</code> with the addition of <code>on_each_release_fn</code> which is invoked every time the key for the tap dance is released. It is worth noting that <code>on_each_release_fn</code> will still be called even when the key is released after the dance finishes (e.g. if the key is released after being pressed and held for longer than the <code>TAPPING_TERM</code>).</li></ul><p>The first option is enough for a lot of cases, that just want dual roles. For example, <code>ACTION_TAP_DANCE_DOUBLE(KC_SPC, KC_ENT)</code> will result in <code>Space</code> being sent on single-tap, <code>Enter</code> otherwise.</p><divclass="warning custom-block"><pclass="custom-block-title">WARNING</p><p>Keep in mind that only <ahref="./../keycodes_basic">basic keycodes</a> are supported here. Custom keycodes are not supported.</p></div><p>Similar to the first option, the second and third option are good for simple layer-switching cases.</p><p>For more complicated cases, like blink the LEDs, fiddle with the backlighting, and so on, use the fourth or fifth option. Examples of each are listed below.</p><h2id="implementation"tabindex="-1">Implementation Details <aclass="header-anchor"href="#implementation"aria-label="Permalinkto&
<spanclass="line"><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span></code></pre></div><h3id="complex-examples"tabindex="-1">Complex Examples <aclass="header-anchor"href="#complex-examples"aria-label="Permalink to "Complex Examples {#complex-examples}""></a></h3><p>This section details several complex tap dance examples. All the enums used in the examples are declared like this:</p><divclass="language-c vp-adaptive-theme"><buttontitle="Copy Code"class="copy"></button><spanclass="lang">c</span><preclass="shiki shiki-themes github-light github-dark vp-code"><code><spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// Enums defined for all examples:</span></span>
<spanclass="line"><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span></code></pre></div><h4id="example-2"tabindex="-1">Example 2: Turn LED Lights On Then Off, One at a Time <aclass="header-anchor"href="#example-2"aria-label="Permalink to "Example 2: Turn LED Lights On Then Off, One at a Time {#example-2}""></a></h4><divclass="language-c vp-adaptive-theme"><buttontitle="Copy Code"class="copy"></button><spanclass="lang">c</span><preclass="shiki shiki-themes github-light github-dark vp-code"><code><spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// On each tap, light up one LED, from right to left</span></span>
<spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// On the fourth tap, turn them off from right to left</span></span>
<spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// If the flash state didn't happen, then turn off LEDs, left to right</span></span>
<spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// All tap dances now put together. Example 2 is "CT_FLSH"</span></span>
<spanclass="line"><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span></code></pre></div><h4id="example-3"tabindex="-1">Example 3: Send <code>:</code> on Tap, <code>;</code> on Hold <aclass="header-anchor"href="#example-3"aria-label="Permalink to "Example 3: Send `:` on Tap, `;` on Hold {#example-3}""></a></h4><p>With a little effort, powerful tap-hold configurations can be implemented as tap dances. To emit taps as early as possible, we need to act on releases of the tap dance key. There is no callback for this in the tap dance framework, so we use <code>process_record_user()</code>.</p><divclass="language-c vp-adaptive-theme"><buttontitle="Copy Code"class="copy"></button><spanclass="lang">c</span><preclass="shiki shiki-themes github-light github-dark vp-code"><code><spanclass="line"><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">typedef</span><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;"> struct</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<spanclass="line"><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><spanstyle="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> TD</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(CT_CLN):</span><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // list all tap dance keycodes with tap-hold configurations</span></span>
<spanclass="line"><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span></code></pre></div><h4id="example-4"tabindex="-1">Example 4: 'Quad Function Tap-Dance'<aclass="header-anchor"href="#example-4"aria-label="Permalink to "Example 4: 'Quad Function Tap-Dance' {#example-4}""></a></h4><p>By <ahref="https://github.com/danielggordon"target="_blank"rel="noreferrer">DanielGGordon</a></p><p>Allow one key to have 4 (or more) functions, depending on number of presses, and if the key is held or tapped. Below is a specific example:</p><ul><li>Tap = Send <code>x</code></li><li>Hold = Send <code>Control</code></li><li>Double Tap = Send <code>Escape</code></li><li>Double Tap and Hold = Send <code>Alt</code></li></ul><p>You will need a few things that can be used for 'Quad Function Tap-Dance'.</p><p>You'll need to add these to the top of your <code>keymap.c</code> file, before your keymap.</p><divclass="language-c vp-adaptive-theme"><buttontitle="Copy Code"class="copy"></button><spanclass="lang">c</span><preclass="shiki shiki-themes github-light github-dark vp-code"><code><spanclass="line"><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">typedef</span><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;"> enum</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<spanclass="line"><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> TD_DOUBLE_SINGLE_TAP,</span><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // Send two single taps</span></span>
<spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// For the x tap dance. Put it here so it can be used in any keymap</span></span>
<spanclass="line"><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">void</span><spanstyle="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> x_reset</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><spanstyle="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">tap_dance_state_t</span><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;"> *</span><spanstyle="--shiki-light:#E36209;--shiki-dark:#FFAB70;">state</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">void</span><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;"> *</span><spanstyle="--shiki-light:#E36209;--shiki-dark:#FFAB70;">user_data</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span></code></pre></div><p>Now, at the bottom of your <code>keymap.c</code> file, you'll need to add the following:</p><divclass="language-c vp-adaptive-theme"><buttontitle="Copy Code"class="copy"></button><spanclass="lang">c</span><preclass="shiki shiki-themes github-light github-dark vp-code"><code><spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;">/* Return an integer that corresponds to what kind of tap dance should be executed.</span></span>
<spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> * How to figure out tap dance state: interrupted and pressed.</span></span>
<spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> * Interrupted: If the state of a dance is "interrupted", that means that another key has been hit</span></span>
<spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> * under the tapping term. This is typically indicitive that you are trying to "tap" the key.</span></span>
<spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> * Pressed: Whether or not the key is still being pressed. If this value is true, that means the tapping term</span></span>
<spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> * has ended, but the key is still being pressed down. This generally means the key is being "held".</span></span>
<spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> * One thing that is currenlty not possible with qmk software in regards to tap dance is to mimic the "permissive hold"</span></span>
<spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> * feature. In general, advanced tap dances do not work well if they are used with commonly typed letters.</span></span>
<spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> * For example "A". Tap dances are best used on non-letter keys that are not hit while typing letters.</span></span>
<spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> * Good places to put an advanced tap dance:</span></span>
<spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> * z,q,x,j,k,v,b, any function key, home/end, comma, semi-colon</span></span>
<spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> * Criteria for "good placement" of a tap dance key:</span></span>
<spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> * Not a key that is hit frequently in a sentence</span></span>
<spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> * Not a key that is used frequently to double tap, for example 'tab' is often double tapped in a terminal, or</span></span>
<spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> * in a web form. So 'tab' would be a poor choice for a tap dance.</span></span>
<spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> * Letters used in common words as a double. For example 'p' in 'pepper'. If a tap dance function existed on the</span></span>
<spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> * letter 'p', the word 'pepper' would be quite frustating to type.</span></span>
<spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> * For the third point, there does exist the 'TD_DOUBLE_SINGLE_TAP', however this is not fully tested</span></span>
<spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // Key has not been interrupted, but the key is still held. Means you want to send a 'HOLD'.</span></span>
<spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // TD_DOUBLE_SINGLE_TAP is to distinguish between typing "pepper", and actually wanting a double tap</span></span>
<spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // action when hitting 'pp'. Suggested use case for this return value is when you want to send two</span></span>
<spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // keystrokes of the key, and not the 'double tap' action/macro.</span></span>
<spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // Assumes no one is trying to type the same letter three times (at least not quickly).</span></span>
<spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // If your tap dance key is 'KC_W', and you want to type "www." quickly - then you will need to add</span></span>
<spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // an exception here to return a 'TD_TRIPLE_SINGLE_TAP', and define that enum just like 'TD_DOUBLE_SINGLE_TAP'</span></span>
<spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// Create an instance of 'td_tap_t' for the 'x' tap dance.</span></span>
<spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // Last case is for fast typing. Assuming your key is `f`:</span></span>
<spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // For example, when typing the word `buffer`, and you want to make sure that you send `ff` and not `Esc`.</span></span>
<spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // In order to type `ff` when typing fast, the next character will have to be hit within the `TAPPING_TERM`, which by default is 200ms.</span></span>
<spanclass="line"><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span></code></pre></div><p>And then simply use <code>TD(X_CTL)</code> anywhere in your keymap.</p><divclass="info custom-block"><pclass="custom-block-title">INFO</p><p>In this configuration "hold" takes place <strong>after</strong> tap dance timeout. To achieve instant hold, remove <code>state->interrupted</code> checks in conditions. As a result you may use comfortable longer tapping periods to have more time for taps and not to wait too long for holds (try starting with doubled <code>TAPPING_TERM</code>).</p></div><h4id="example-5"tabindex="-1">Example 5: Using tap dance for advanced mod-tap and layer-tap keys <aclass="header-anchor"href="#example-5"aria-label="Permalink to "Example 5: Using tap dance for advanced mod-tap and layer-tap keys {#example-5}""></a></h4><p>Tap dance can be used to emulate <code>MT()</code> and <code>LT()</code> behavior when the tapped code is not a basic keycode. This is useful to send tapped keycodes that normally require <code>Shift</code>, such as parentheses or curly braces—or other modified keycodes, such as <code>Control + X</code>.</p><p>Below your layers and custom keycodes, add the following:</p><divclass="language-c vp-adaptive-theme"><buttontitle="Copy Code"class="copy"></button><spanclass="lang">c</span><preclass="shiki shiki-themes github-light github-dark vp-code"><code><spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// Tap Dance keycodes</span></span>
<spanclass="line"><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ALT_LP</span><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // Our example key: `LALT` when held, `(` when tapped. Add additional keycodes for each tapdance.</span></span>
<spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// Define a type containing as many tapdance states as you need</span></span>
<spanclass="line"><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">void</span><spanstyle="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> altlp_reset</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><spanstyle="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">tap_dance_state_t</span><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;"> *</span><spanstyle="--shiki-light:#E36209;--shiki-dark:#FFAB70;">state</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">void</span><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;"> *</span><spanstyle="--shiki-light:#E36209;--shiki-dark:#FFAB70;">user_data</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span></code></pre></div><p>Below your <code>LAYOUT</code>, define each of the tapdance functions:</p><divclass="language-c vp-adaptive-theme"><buttontitle="Copy Code"class="copy"></button><spanclass="lang">c</span><preclass="shiki shiki-themes github-light github-dark vp-code"><code><spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// Determine the tapdance state to return</span></span>
<spanclass="line"><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;"> else</span><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> TD_UNKNOWN;</span><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // Any number higher than the maximum state value you return above</span></span>
<spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// Handle the possible states for each tapdance keycode you define:</span></span>
<spanclass="line"><spanstyle="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> register_mods</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><spanstyle="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">MOD_BIT</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(KC_LALT));</span><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // For a layer-tap key, use `layer_on(_MY_LAYER)` here</span></span>
<spanclass="line"><spanstyle="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> unregister_mods</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><spanstyle="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">MOD_BIT</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(KC_LALT));</span><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // For a layer-tap key, use `layer_off(_MY_LAYER)` here</span></span>
<spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// Define `ACTION_TAP_DANCE_FN_ADVANCED()` for each tapdance keycode, passing in `finished` and `reset` functions</span></span>
<spanclass="line"><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span></code></pre></div><p>Wrap each tapdance keycode in <code>TD()</code> when including it in your keymap, e.g. <code>TD(ALT_LP)</code>.</p><h4id="example-6"tabindex="-1">Example 6: Using tap dance for momentary-layer-switch and layer-toggle keys <aclass="header-anchor"href="#example-6"aria-label="Permalink to "Example 6: Using tap dance for momentary-layer-switch and layer-toggle keys {#example-6}""></a></h4><p>Tap Dance can be used to mimic MO(layer) and TG(layer) functionality. For this example, we will set up a key to function as <code>KC_QUOT</code> on single-tap, as <code>MO(_MY_LAYER)</code> on single-hold, and <code>TG(_MY_LAYER)</code> on double-tap.</p><p>The first step is to include the following code towards the beginning of your <code>keymap.c</code>:</p><divclass="language-c vp-adaptive-theme"><buttontitle="Copy Code"class="copy"></button><spanclass="lang">c</span><preclass="shiki shiki-themes github-light github-dark vp-code"><code><spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// Define a type for as many tap dance states as you need</span></span>
<spanclass="line"><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> QUOT_LAYR,</span><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // Our custom tap dance key; add any other tap dance keys to this enum </span></span>
<spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// Declare the functions to be used with your tap dance key(s)</span></span>
<spanclass="line"></span>
<spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// Function associated with all tap dances</span></span>
<spanclass="line"><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">void</span><spanstyle="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> ql_reset</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><spanstyle="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">tap_dance_state_t</span><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;"> *</span><spanstyle="--shiki-light:#E36209;--shiki-dark:#FFAB70;">state</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">void</span><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;"> *</span><spanstyle="--shiki-light:#E36209;--shiki-dark:#FFAB70;">user_data</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span></code></pre></div><p>Towards the bottom of your <code>keymap.c</code>, include the following code:</p><divclass="language-c vp-adaptive-theme"><buttontitle="Copy Code"class="copy"></button><spanclass="lang">c</span><preclass="shiki shiki-themes github-light github-dark vp-code"><code><spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// Determine the current tap dance state</span></span>
<spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// Initialize tap structure associated with example tap dance key</span></span>
<spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // If the key was held down and now is released then switch off the layer</span></span>
<spanclass="line"><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre></div><p>The above code is similar to that used in previous examples. The one point to note is that we need to be able to check which layers are active at any time so we can toggle them if needed. To do this we use the <code>layer_state_is(layer)</code> function which returns <code>true</code> if the given <code>layer</code> is active.</p><p>The use of <code>cur_dance()</code> and <code>ql_tap_state</code> mirrors the above examples.</p><p>The <code>case: TD_SINGLE_TAP</code> in <code>ql_finished</code> is similar to the above examples. The <code>TD_SINGLE_HOLD</code> case works in conjunction with <code>ql_reset()</code> to switch to <code>_MY_LAYER</code> while the tap dance key is held, and to switch away from <code>_MY_LAYER</code> when the key is released. This mirrors the use of <code>MO(_MY_LAYER)</code>. The <code>TD_DOUBLE_TAP</code> case works by checking whether <code>_MY_LAYER</code> is the active layer, and toggling it on or off accordingly. This mirrors the use of <code>TG(_MY_LAYER)</code>.</p><p><code>tap_dance_actions[]</code> works similar to the above examples. Note that, additionally, I set a longer tapping term for the tap dance keys. This is because I like my <code>TAPPING_TERM</code> to be short (~175ms) for my non-tap-dance keys but find that this is too quick for me to reliably complete tap dance actions - thus the increased time of 275ms here. In order for the per-key tapping terms to take effect, <code>TAPPING_TERM_PER_KEY</code> must be defined in your <code>config.h</code>.</p><p>Finally, to get this tap dance key working, be sure to include <code>TD(QUOT_LAYR)</code> in your <code>keymaps[]</code>.</p></div></div></main><footerclass="VPDocFooter"data-v-39a288b8data-v-09de1c0f><!--[--><!--]--><!----><navclass="prev-next"data-v-09de1c0f><divclass="pager"data-v-09de1c0f><aclass="VPLink link pager-link prev"href="/features/swap_hands"data-v-09de1c0f><!--[--><spanclass="desc"data-v-09de1c0f>Previous page</span><spanclass="title"data-v-09de1c0f>Swap Hands</span><!--]--></a></div><divclass="pager"data-v-09de1c0f><aclass="VPLink link pager-link next"href="/tap_hold"data-v-09de1c0f><!--[--><spanclass="desc"data-v-09de1c0f>Next page</span><spanclass="title"data-v-09de1c0f>Tap-Hold Configuration</span><!--]--></a></div></nav></footer><!--[--><!--]--></div></div></div><!--[--><!--]--></div></div><!----><!--[--><!--]--></div></div>