qmk_firmware/assets/custom_quantum_functions.md.CchHkQ2j.js

16 lines
60 KiB
JavaScript
Raw Normal View History

import { _ as _export_sfc, c as createElementBlock, o as openBlock, a8 as createStaticVNode } from "./chunks/framework.B9AX-CPi.js";
const __pageData = JSON.parse(`{"title":"How to Customize Your Keyboard's Behavior","description":"","frontmatter":{},"headers":[],"relativePath":"custom_quantum_functions.md","filePath":"custom_quantum_functions.md"}`);
const _sfc_main = { name: "custom_quantum_functions.md" };
const _hoisted_1 = /* @__PURE__ */ createStaticVNode('<h1 id="how-to-customize-your-keyboard-s-behavior" tabindex="-1">How to Customize Your Keyboard&#39;s Behavior <a class="header-anchor" href="#how-to-customize-your-keyboard-s-behavior" aria-label="Permalink to &quot;How to Customize Your Keyboard&#39;s Behavior&quot;"></a></h1><p>For a lot of people a custom keyboard is about more than sending button presses to your computer. You want to be able to do things that are more complex than simple button presses and macros. QMK has hooks that allow you to inject code, override functionality, and otherwise customize how your keyboard behaves in different situations.</p><p>This page does not assume any special knowledge about QMK, but reading <a href="./understanding_qmk">Understanding QMK</a> will help you understand what is going on at a more fundamental level.</p><h2 id="a-word-on-core-vs-keyboards-vs-keymap" tabindex="-1">A Word on Core vs Keyboards vs Keymap <a class="header-anchor" href="#a-word-on-core-vs-keyboards-vs-keymap" aria-label="Permalink to &quot;A Word on Core vs Keyboards vs Keymap {#a-word-on-core-vs-keyboards-vs-keymap}&quot;"></a></h2><p>We have structured QMK as a hierarchy:</p><ul><li>Core (<code>_quantum</code>) <ul><li>Keyboard/Revision (<code>_kb</code>) <ul><li>Keymap (<code>_user</code>)</li></ul></li></ul></li></ul><p>Each of the functions described below can be defined with a <code>_kb()</code> suffix or a <code>_user()</code> suffix. We intend for you to use the <code>_kb()</code> suffix at the Keyboard/Revision level, while the <code>_user()</code> suffix should be used at the Keymap level.</p><p>When defining functions at the Keyboard/Revision level it is important that your <code>_kb()</code> implementation call <code>_user()</code> before executing anything else- otherwise the keymap level function will never be called.</p><h1 id="custom-keycodes" tabindex="-1">Custom Keycodes <a class="header-anchor" href="#custom-keycodes" aria-label="Permalink to &quot;Custom Keycodes&quot;"></a></h1><p>By far the most common task is to change the behavior of an existing keycode or to create a new keycode. From a code standpoint the mechanism for each is very similar.</p><h2 id="defining-a-new-keycode" tabindex="-1">Defining a New Keycode <a class="header-anchor" href="#defining-a-new-keycode" aria-label="Permalink to &quot;Defining a New Keycode&quot;"></a></h2><p>The first step to creating your own custom keycode(s) is to enumerate them. This means both naming them and assigning a unique number to that keycode. Rather than limit custom keycodes to a fixed range of numbers QMK provides the <code>SAFE_RANGE</code> macro. You can use <code>SAFE_RANGE</code> when enumerating your custom keycodes to guarantee that you get a unique number.</p><p>Here is an example of enumerating 2 keycodes. After adding this block to your <code>keymap.c</code> you will be able to use <code>FOO</code> and <code>BAR</code> inside your keymap.</p><div class="language-c vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">enum</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> my_keycodes {</span></span>\n<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> FOO </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> SAFE_RANGE,</span></span>\n<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> BAR</span></span>\n<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span></code></pre></div><h2 id="programming-the-behavior-of-any-keycode" tabindex="-1">Programming the Behavior of Any Keycode <a class="header-anchor" href="#programming-the-behavior-of-any-keycode" aria-label="Permalink to &quot;Programming the Behavior of Any Keycode {#programming-the-behavio
const _hoisted_125 = [
_hoisted_1
];
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
return openBlock(), createElementBlock("div", null, _hoisted_125);
}
const custom_quantum_functions = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
export {
__pageData,
custom_quantum_functions as default
};