mirror of
https://github.com/qmk/qmk_firmware.git
synced 2025-02-27 01:56:43 +00:00
16 lines
7.1 KiB
JavaScript
16 lines
7.1 KiB
JavaScript
|
import { _ as _export_sfc, c as createElementBlock, o as openBlock, a8 as createStaticVNode } from "./chunks/framework.DyMmIvSC.js";
|
|||
|
const __pageData = JSON.parse('{"title":"How Keys Are Registered, and Interpreted by Computers","description":"","frontmatter":{},"headers":[],"relativePath":"how_keyboards_work.md","filePath":"how_keyboards_work.md"}');
|
|||
|
const _sfc_main = { name: "how_keyboards_work.md" };
|
|||
|
const _hoisted_1 = /* @__PURE__ */ createStaticVNode('<h1 id="how-keys-are-registered-and-interpreted-by-computers" tabindex="-1">How Keys Are Registered, and Interpreted by Computers <a class="header-anchor" href="#how-keys-are-registered-and-interpreted-by-computers" aria-label="Permalink to "How Keys Are Registered, and Interpreted by Computers""></a></h1><p>In this file, you can will learn the concepts of how keyboards work over USB, and you'll be able to better understand what you can expect from changing your firmware directly.</p><h2 id="schematic-view" tabindex="-1">Schematic View <a class="header-anchor" href="#schematic-view" aria-label="Permalink to "Schematic View""></a></h2><p>Whenever you type on 1 particular key, here is the chain of actions taking place:</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code"><code><span class="line"><span>+------+ +-----+ +----------+ +----------+ +----+</span></span>\n<span class="line"><span>| User |-------->| Key |------>| Firmware |----->| USB wire |---->| OS |</span></span>\n<span class="line"><span>+------+ +-----+ +----------+ +----------+ +----+</span></span></code></pre></div><p>This scheme is a very simple view of what's going on, and more details follow in the next sections.</p><h2 id="_1-you-press-a-key" tabindex="-1">1. You Press a Key <a class="header-anchor" href="#_1-you-press-a-key" aria-label="Permalink to "1. You Press a Key""></a></h2><p>Whenever you press a key, the firmware of your keyboard can register this event. It can register when the key is pressed, held and released.</p><p>This usually happens with a periodic scan of key presses. This speed often is limited by the mechanical key response time, the protocol to transfer those key presses (here USB HID), and by the software it is used in.</p><h2 id="_2-what-the-firmware-sends" tabindex="-1">2. What the Firmware Sends <a class="header-anchor" href="#_2-what-the-firmware-sends" aria-label="Permalink to "2. What the Firmware Sends""></a></h2><p>The <a href="https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf" target="_blank" rel="noreferrer">HID specification</a> tells what a keyboard can actually send through USB to have a chance to be properly recognised. This includes a pre-defined list of scancodes which are simple numbers from <code>0x00</code> to <code>0xE7</code>. The firmware assigns a scancode to each key of the keyboard.</p><p>The firmware does not send actual letters or characters, but only scancodes. Thus, by modifying the firmware, you can only modify what scancode is sent over USB for a given key.</p><h2 id="_3-what-the-event-input-kernel-does" tabindex="-1">3. What the Event Input/Kernel Does <a class="header-anchor" href="#_3-what-the-event-input-kernel-does" aria-label="Permalink to "3. What the Event Input/Kernel Does""></a></h2><p>The <em>scancode</em> is mapped to a <em>keycode</em> dependent on the keyboard <a href="https://github.com/systemd/systemd/blob/main/hwdb.d/60-keyboard.hwdb" target="_blank" rel="noreferrer">60-keyboard.hwdb at Main</a>. Without this mapping, the operating system will not receive a valid keycode and will be unable to do anything useful with that key press.</p><h2 id="_4-what-the-operating-system-does" tabindex="-1">4. What the Operating System Does <a class="header-anchor" href="#_4-what-the-operating-system-does" aria-label="Permalink to "4. What the Operating System Does""></a></h2><p>Once the keycode reaches the operating system, a piece of software has to have it match an actual character thanks to a keyboard layout. For example, if your layout is set to QWERTY, a sample of the matching table is as follows:</p><table><thead><tr><th>keycode</th><th>character</th></tr></thead><tbody><tr><td>0x04</td><td>a/A</td></tr><tr><td>0x05</td><td>b/B</td></tr><tr><td>0x06</td><td>c
|
|||
|
const _hoisted_28 = [
|
|||
|
_hoisted_1
|
|||
|
];
|
|||
|
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|||
|
return openBlock(), createElementBlock("div", null, _hoisted_28);
|
|||
|
}
|
|||
|
const how_keyboards_work = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
|
|||
|
export {
|
|||
|
__pageData,
|
|||
|
how_keyboards_work as default
|
|||
|
};
|