Peter's keyboard firmware (QMK)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long. 3.5KB

  1. # How Keys Are Registered, and Interpreted by Computers
  2. In this file, you can will learn the concepts of how keyboards work over USB,
  3. and you'll be able to better understand what you can expect from changing your
  4. firmware directly.
  5. ## Schematic View
  6. Whenever you type on 1 particular key, here is the chain of actions taking
  7. place:
  8. ``` text
  9. +------+ +-----+ +----------+ +----------+ +----+
  10. | User |-------->| Key |------>| Firmware |----->| USB wire |---->| OS |
  11. +------+ +-----+ +----------+ +----------+ +----+
  12. ```
  13. This scheme is a very simple view of what's going on, and more details follow
  14. in the next sections.
  15. ## 1. You Press a Key
  16. Whenever you press a key, the firmware of your keyboard can register this event.
  17. It can register when the key is pressed, held and released.
  18. 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.
  19. ## 2. What the Firmware Sends
  20. The [HID specification]( 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 `0x00` to `0xE7`. The firmware assigns a scancode to each key of the keyboard.
  21. The firmware does not send actual letters or characters, but only scancodes.
  22. Thus, by modifying the firmware, you can only modify what scancode is sent over
  23. USB for a given key.
  24. ## 3. What the Operating System Does
  25. Once the keycode reaches the operating system, a piece of software has to have
  26. it match an actual character thanks to a keyboard layout. For example, if your
  27. layout is set to QWERTY, a sample of the matching table is as follows:
  28. | keycode | character |
  29. |---------|-----------|
  30. | 0x04 | a/A |
  31. | 0x05 | b/B |
  32. | 0x06 | c/C |
  33. | ... | ... |
  34. | 0x1C | y/Y |
  35. | 0x1D | z/Z |
  36. | ... | ... |
  37. ## Back to the Firmware
  38. As the layout is generally fixed (unless you create your own), the firmware can actually call a keycode by its layout name directly to ease things for you. This is exactly what is done here with `KC_A` actually representing `0x04` in QWERTY. The full list can be found in [keycodes](
  39. ## List of Characters You Can Send
  40. Putting aside shortcuts, having a limited set of keycodes mapped to a limited layout means that **the list of characters you can assign to a given key are only the ones present in the layout**.
  41. For example, this means that if you have a QWERTY US layout, and you want to assign one key to produce `€` (euro currency symbol), you are unable to do so, because the QWERTY US layout does not have such mapping. You could fix that by using a QWERTY UK layout, or a QWERTY US International.
  42. You may wonder why a keyboard layout containing all of Unicode is not devised then? The limited number of keycodes available through USB simply disallows such a thing.
  43. ## How to (Maybe) Enter Unicode Characters
  44. You can have the firmware send *sequences of keys* to use the [software Unicode Input Method]( of the target operating system, thus effectively entering characters independently of the layout defined in the OS.
  45. Yet, it does come with multiple disadvantages:
  46. - Tied to a specific OS a a time (need recompilation when changing OS);
  47. - Within a given OS, does not work in all software;
  48. - Limited to a subset of Unicode on some systems.