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:
- press and hold down ALT
- enter a decimal number from
0-255via the numerical keypad - 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 correspondingmap[]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
- debian bookworm: freebsd-manpages 12.2-1 ยท BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 ยท BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 ยท BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 ยท BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 ยท BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 ยท BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms