# 1.1 Keyboard Fundamentals

A keyboard is an arrangement of keys that when pressed, sends a `key code` to a keyboard driver. `Key codes` are all the keys like Alphanumeric(a, b, 1, 2), modifier(ctrl, alt/option), arrow keys and many more. All the keys on a keyboard form a `keyboard layout` that represents a collection of keys and their position. There are some common layouts that even have names such as qwerty, colemak, and dvorak that are shown below.

![qwerty layout](https://3776368646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKoZa1xwxAlOy01IlxMgW%2Fuploads%2Fo1hoEBGRH53C0ryuZ7Hv%2Fimage.png?alt=media\&token=38b84440-5892-466b-8277-dacf79a7881d)

![dvorak layout](https://3776368646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKoZa1xwxAlOy01IlxMgW%2Fuploads%2FdITg82jvsW3lAKMBxIMl%2Fimage.png?alt=media\&token=5b75e20a-9d3c-4884-a882-72975e91c3af)



![colmak layout](https://3776368646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKoZa1xwxAlOy01IlxMgW%2Fuploads%2FH8cci9ksO2eezyWgiDCU%2Fimage.png?alt=media\&token=3c0fb0d5-88f4-40d0-bc58-04ecc0df7986)

The purpose of a keyboard is to be an input device to communicate information to your computer. If a key outputs a single code, then there would be a one-to-one relationship, where each key gets a single keycode output. This is quite impractical and would require lots of rows and keys like in the picture below.

![](https://3776368646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKoZa1xwxAlOy01IlxMgW%2Fuploads%2Fn7zlFQ5svamdsCaQIInd%2FScreen%20Shot%202022-05-30%20at%208.05.33%20PM.png?alt=media\&token=5ce1e44d-30a9-4293-8b00-e818d43499dc)

A key can instead have a one-to-many relationship with the help of `layer activators.` Layer activators are the keycodes like the shift and capslock keys. When the shift activators is activated keys switch output from lowercase letters to upper case letters. This creates a one-to-two relationship, where one key can have 2 possible output states, lower and upper. When talking about just the lowercase keys or uppercase keys on the layout, it is called a `layer` followed by a description word. So the starting layout is made of 2 layers, the default layer or base layer containing lower case keys and the upper, shift or caps layer containing the uppercase letters.

{% hint style="success" %}
A layer is the collection of the keycodes with their position and typically have a theme
{% endhint %}

There are many more keyboard layers, such as the function layer(Fn), number layer and navigation layer and many more that will be discussed later. Together, all these keyboard layers can be grouped together to create a \`keymap\`. A Keymap is useful if you move between keyboards or want to share all the layers at once.



```markup
Keymap: 32 Layers                   Layer: action code matrix
-----------------                   ---------------------
stack of layers                     array_of_action_code[row][column]
       ____________ precedence               _______________________
      /           / | high                  / ESC / F1  / F2  / F3   ....
  31 /___________// |                      /-----/-----/-----/-----
  30 /___________// |                     / TAB /  Q  /  W  /  E   ....
  29 /___________/  |                    /-----/-----/-----/-----
   :   _:_:_:_:_:__ |               :   /LCtrl/  A  /  S  /  D   ....
   :  / : : : : : / |               :  /  :     :     :     :
   2 /___________// |               2 `--------------------------
   1 /___________// |               1 `--------------------------
   0 /___________/  V low           0 `--------------------------
```

Picture of a keymap made from layers from [QMK](https://docs.qmk.fm/#/keymap) docs.\
