<spanclass="line"><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">#define</span><spanstyle="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> ONESHOT_TIMEOUT</span><spanstyle="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 5000</span><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> /* Time (in ms) before the one shot key is released */</span></span></code></pre></div><ul><li><code>OSM(mod)</code> - Momentarily hold down <em>mod</em>. You must use the <code>MOD_*</code> keycodes as shown in <ahref="./mod_tap">Mod Tap</a>, not the <code>KC_*</code> codes.</li><li><code>OSL(layer)</code> - momentary switch to <em>layer</em>.</li><li><code>OS_ON</code> - Turns on One Shot keys.</li><li><code>OS_OFF</code> - Turns off One Shot keys. OSM act as regular mod keys, OSL act like <code>MO</code>.</li><li><code>OS_TOGG</code> - Toggles the one shot key status.</li></ul><p>Sometimes, you want to activate a one-shot key as part of a macro or tap dance routine.</p><p>For one shot layers, you need to call <code>set_oneshot_layer(LAYER, ONESHOT_START)</code> on key down, and <code>clear_oneshot_layer_state(ONESHOT_PRESSED)</code> on key up. If you want to cancel the oneshot, call <code>reset_oneshot_layer()</code>.</p><p>For one shot mods, you need to call <code>set_oneshot_mods(MOD_BIT(KC_*))</code> to set it, or <code>clear_oneshot_mods()</code> to cancel it.</p><divclass="warning custom-block"><pclass="custom-block-title">WARNING</p><p>If you're having issues with OSM translating over Remote Desktop Connection, this can be fixed by opening the settings, going to the "Local Resources" tab, and in the keyboard section, change the drop down to "On this Computer". This will fix the issue and allow OSM to function properly over Remote Desktop.</p></div><h2id="callbacks"tabindex="-1">Callbacks <aclass="header-anchor"href="#callbacks"aria-label="Permalink to "Callbacks""></a></h2><p>When you'd like to perform custom logic when pressing a one shot key, there are several callbacks you can choose to implement. You could indicate changes in one shot keys by flashing an LED or making a sound, for example.</p><p>There is a callback for <code>OSM(mod)</code>. It is called whenever the state of any one shot modifier key is changed: when it toggles on, but also when it is toggled off. You can use it 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:#D73A49;--shiki-dark:#F97583;">void</span><spanstyle="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> oneshot_mods_changed_user</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">uint8_t</span><spanstyle="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> mods</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<spanclass="line"><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre></div><p>The <code>mods</code> argument contains the active mods after the change, so it reflects the current state.</p><p>When you use One Shot Tap Toggle (by adding <code>#define ONESHOT_TAP_TOGGLE 2</code> in your <code>config.h</code> file), you may lock a modifier key by pressing it the specified amount of times. There's a callback for that, too:</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;">void</span><spanstyle="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> oneshot_locked_mods_changed_user</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">uint8_t</span><spanstyle="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> mods</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<spanclass="line"><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre></div><p>Last, there is also a callback for the <code>OSL(layer)</code> one shot key:</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;">void</span><spanstyle="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> oneshot_layer_changed_user</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">uint8_t</span><spanstyle="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> layer</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<spanclass="line"><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre></div><p>If any one shot layer is switched off, <code>layer</code> will be zero. When you're looking to do something on any layer change instead of one shot layer changes, <code>layer_state_set_user</code> is a better callback to use.</p><p>If you are making your own keyboard, there are also <code>_kb</code> equivalent 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:#D73A49;--shiki-dark:#F97583;">void</span><spanstyle="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> oneshot_locked_mods_changed_kb</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">uint8_t</span><spanstyle="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> mods</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<spanclass="line"><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">void</span><spanstyle="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> oneshot_layer_changed_kb</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">uint8_t</span><spanstyle="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> layer</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span></code></pre></div><p>As with any callback, be sure to call the <code>_user</code> variant to allow for further customizability.</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="/feature_layers"data-v-09de1c0f><!--[--><spanclass="desc"data-v-09de1c0f>Previous page</span><spanclass="title"data-v-09de1c0f>Layers</span><!--]--></a></div><divclass="pager"data-v-09de1c0f><aclass="VPLink link pager-link next"href="/features/os_detection"data-v-09de1c0f><!--[--><spanclass="desc"data-v-09de1c0f>Next page</span><spanclass="title"data-v-09de1c0f>OS Detection</span><!--]--></a></div></nav></footer><!--[--><!--]--></div></div></div><!--[--><!--]--></div></div><!----><!--[--><!--]--></div></div>