aboutsummaryrefslogtreecommitdiff
path: root/docs/basic_how_keyboards_work.md
diff options
context:
space:
mode:
Diffstat (limited to 'docs/basic_how_keyboards_work.md')
-rw-r--r--docs/basic_how_keyboards_work.md96
1 files changed, 96 insertions, 0 deletions
diff --git a/docs/basic_how_keyboards_work.md b/docs/basic_how_keyboards_work.md
new file mode 100644
index 000000000..73c3f5c5f
--- /dev/null
+++ b/docs/basic_how_keyboards_work.md
@@ -0,0 +1,96 @@
1# How keys are registered, and interpreted by computers
2
3In this file, you can will learn the concepts of how keyboards work over USB,
4and you'll be able to better understand what you can expect from changing your
5firmware directly.
6
7## Schematic view
8
9Whenever you type on 1 particular key, here is the chain of actions taking
10place:
11
12``` text
13+------+ +-----+ +----------+ +----------+ +----+
14| User |-------->| Key |------>| Firmware |----->| USB wire |---->| OS |
15+------+ +-----+ +----------+ +----------+ |----+
16```
17
18This scheme is a very simple view of what's going on, and more details follow
19in the next sections.
20
21## 1. You Press a Key
22
23Whenever you press a key, the firmware of your keyboard can register this event.
24It can register when the key is pressed, held and released.
25
26This usually happens with a [periodic scan of key presses with a frequency around 100 hz](https://github.com/benblazak/ergodox-firmware/blob/master/references.md#typical-keyboard-information).
27This speed often is limited by the mechanical key response time, the protocol
28to transfer those key presses (here USB HID), and by the software it is used in.
29
30## 2. What the Firmware Sends
31
32The [HID specification](http://www.usb.org/developers/hidpage/Hut1_12v2.pdf)
33tells what a keyboard can actually send through USB to have a chance to be
34properly recognised. This includes a pre-defined list of keycodes which are
35simple numbers from `0x00` to `0xE7`. The firmware assigns a keycode to each
36key of the keyboard.
37
38The firmware does not send actually letters or characters, but only keycodes.
39Thus, by modifying the firmware, you only can modify what keycode is sent over
40USB for a given key.
41
42## 3. What the Operating System Does
43
44Once the keycode reaches the operating system, a piece of software has to have
45it match an actual character thanks to a keyboard layout. For example, if your
46layout is set to QWERTY, a sample of the matching table is as follow:
47
48``` text
49| keycode | character |
50|---------+-----------|
51| 0x04 | a/A |
52| 0x05 | b/B |
53| 0x06 | c/C |
54| ... | ... |
55| 0x1C | y/Y |
56| 0x1D | z/Z |
57| ... | ... |
58|---------+-----------|
59```
60
61## Back to the firmware
62
63As the layout is generally fixed (unless you create your own), the firmware can
64actually call a keycode by its layout name directly to ease things for you.
65
66This is exactly what is done here with `KC_A` actually representing `0x04` in
67QWERTY. The full list can be found in `keycode.txt`.
68
69## List of Characters You Can Send
70
71Putting aside shortcuts, having a limited set of keycodes mapped to a limited
72layout means that **the list of characters you can assign to a given key only
73is the ones present in the layout**.
74
75For example, this means that if you have a QWERTY US layout, and you want to
76assign 1 key to produce `€` (euro currency symbol), you are unable to do so,
77because the QWERTY US layout does not have such mapping. You could fix that by
78using a QWERTY UK layout, or a QWERTY US International.
79
80You may wonder why a keyboard layout containing all of Unicode is not devised
81then? The limited number of keycode available through USB simply disallow such
82a thing.
83
84## How to (Maybe) Enter Unicode Characters
85
86You can have the firmware send *sequences of keys* to use the [software Unicode
87Input
88Method](https://en.wikipedia.org/wiki/Unicode_input#Hexadecimal_code_input) of
89the target operating system, thus effectively entering characters independently
90of the layout defined in the OS.
91
92Yet, it does come with multiple disadvantages:
93
94 - Tied to a specific OS a a time (need recompilation when changing OS);
95 - Within a given OS, does not work in all software;
96 - Limited to a subset of Unicode on some systems.