KEYBOARD(4)

๐Ÿ’– KEYBOARD(4) ๐Ÿ’–

okay bestie, gather round, because today we're talking about the kernel interfaces manual page for keyboard โ€” aka the pc keyboard interface ๐ŸŽนโœจ no cap, this one is a whole vibe.


โœจ NAME โœจ

keyboard โ€” the pc keyboard interface, and yes she is that girl ๐Ÿ’…


๐ŸŒธ DESCRIPTION ๐ŸŒธ

okay so. the PC keyboard is literally the console character input device, like that's her job ๐Ÿซถ. she is owned by the current virtual console โ€” one console at a time, she's not sharing, main character energy only ๐Ÿ‘‘.

want to switch between virtual consoles? use the sequence ALT+Fn โ€” which means hold down ALT and press one of the function keys, fr fr. the virtual console with the same number as the function key you pressed then becomes the current virtual console and gets exclusive use of the keyboard and display ๐Ÿ˜ค iconic behaviour honestly.

๐ŸŽ€ the sneaky keysequence thing ๐ŸŽ€

the console lets you enter values that are not physically present on the keyboard via a special keysequence, which is giving secret menu at in-n-out:

  1. press and hold down ALT
  2. enter a decimal number from 0-255 via the numerical keypad
  3. release ALT

the entered value is then used as the ASCII value for one character. so yeah, you can enter any ASCII value even if your keyboard doesn't have a key for it. slay ๐ŸŒˆ.

๐Ÿ“œ the history function ๐Ÿ“œ

the console driver also includes a history function, activated by pressing the scroll-lock key. this holds the display, and enables the cursor arrows for scrolling up and down through the last scrolled out lines. it's giving time travel but make it terminal โณ๐Ÿ’–

๐Ÿฆ‹ configurable, as she should be ๐Ÿฆ‹

the keyboard is configurable to suit the individual user and the different national layout. periodt.

the keys on the keyboard can have any of the following functions:

  • Normal key โ€” enters the ASCII value associated with the key.
  • Function key โ€” enters a string of ASCII values.
  • Switch Key โ€” switches virtual console.
  • Modifier Key โ€” changes the meaning of another key.

๐Ÿ”ข scancodes, aka the key lore ๐Ÿ”ข

the keyboard is seen as a number of keys numbered from 1 to n. this number is often referred to as the "scancode" for a given key. the number of the key is transmitted as an 8 bit char with bit 7 as 0 when a key is pressed, and the number with bit 7 as 1 when released. this makes it possible to make the mapping of the keys fully configurable ๐Ÿ˜Œโœจ

๐Ÿงš the PIO_KEYMAP ioctl ๐Ÿงš

the meaning of every key is programmable via the PIO_KEYMAP ioctl call, which takes a structure keymap_t as argument. the layout of this structure is as follows:

struct keymap {
        u_short n_keys;
        struct key_t {
                u_char map[NUM_STATES];
                u_char spcl;
                u_char flgs;
        } key[NUM_KEYS];
};

the field n_keys tells the system how many keydefinitions (scancodes) follows. each scancode is then specified in the key_t substructure ๐Ÿซถ

๐Ÿ’ซ the eight states ๐Ÿ’ซ

each scancode can be translated to any of 8 different values, depending on the shift, control, and alt state. these eight possibilities are represented by the map array, as shown below:

                                                               alt
 scan                          cntrl          alt    alt   cntrl
 code     base   shift  cntrl  shift   alt   shift  cntrl  shift
 map[n]      0       1      2      3     4       5      6      7
 ----     ------------------------------------------------------
 0x1E      'a'     'A'   0x01   0x01    'a'    'A'   0x01   0x01

this is the default mapping for the key labelled 'A' which normally has scancode 0x1E โœจ. the eight states are as shown, giving the 'A' key its normal behavior. lowkey elegant.

๐Ÿ”ฎ the spcl field ๐Ÿ”ฎ

the spcl field is used to give the key "special" treatment, and is interpreted as follows. each bit corresponds to one of the states above:

  • if the bit is 0 โ†’ the key emits the number defined in the corresponding map[] entry.
  • if the bit is 1 โ†’ the key is "special", meaning it does not emit anything; instead it changes the "state".

so it's a shift, control, alt, lock, switch-screen, function-key or no-op key. and here's the little twist bestie โ€” the bitmap is backwards, i.e., 7 for base, 6 for shift, etc. ๐Ÿ™ˆ

๐ŸŒŸ the flgs field ๐ŸŒŸ

the flgs field defines if the key should react on caps-lock (1), num-lock (2), both (3) or ignore both (0).

๐Ÿ› ๏ธ kbdcontrol(1) enters the chat ๐Ÿ› ๏ธ

the kbdcontrol(1) utility is used to load such a description into/outof the kernel at runtime. this makes it possible to change the key assignments at runtime, or more important to get (via the GIO_KEYMAP ioctl) the exact key meanings from the kernel (e.g. used by the X server) ๐Ÿ‘‘๐Ÿ’–

โญ function keys โญ

the function keys can be programmed using the SETFKEY ioctl call. this ioctl takes an argument of the type fkeyarg_t:

struct fkeyarg {
        u_short keynum;
        char    keydef[MAXFK];
        char    flen;
};

the field keynum defines which function key that is programmed. the array keydef should contain the new string to be used (MAXFK long), and the length should be entered in flen ๐Ÿ’ซ

the GETFKEY ioctl call works in a similar manner, except it returns the current setting of keynum ๐ŸŒธ

๐ŸŽน the function key numbering, in all her glory ๐ŸŽน

F1-F12                  key 1 - 12
Shift F1-F12            key 13 - 24
Ctrl F1-F12             key 25 - 36
Ctrl+shift F1-F12       key 37 - 48

Home                    key 49
Up arrow                key 50
Page Up                 key 51
(keypad) -              key 52
Left arrow              key 53
(keypad) 5              key 54
Right arrow             key 55
(keypad) +              key 56
End                     key 57
Down arrow              key 58
Page down               key 59
Insert                  key 60
Delete                  key 61

Left window             key 62
Right window            key 63
Menu                    key 64

the kbdcontrol(1) utility also allows changing these values at runtime. no cap ๐Ÿ˜Œ


๐Ÿ’œ AUTHORS ๐Ÿ’œ

Sรธren Schmidt <sos@FreeBSD.org> โ€” thank you for your service, king ๐Ÿซก๐Ÿ’–


and that's the whole page bestie!! this one comes from the Debian release, dated January 8, 1995, and it's the KEYBOARD(4) page ๐ŸŽ€ like, a genuine vintage icon, and she ate ๐Ÿ’…โœจ bye ily, go configure ur keyboard ๐Ÿฆ‹

๐Ÿ“ฆ where this page comes from