xref: /freebsd/share/man/man4/keyboard.4 (revision a03411e84728e9b267056fd31c7d1d9d1dc1b01e)
1.\"
2.Dd January 8, 1995
3.Dt KEYBOARD 4
4.Os
5.Sh NAME
6.Nm keyboard
7.Nd pc keyboard interface
8.Sh DESCRIPTION
9The PC keyboard is used as the console character input device.
10The keyboard
11is owned by the current virtual console.
12To switch between the virtual consoles use the sequence
13.Ar ALT+Fn ,
14which means hold down ALT and press one of the function keys.
15The
16virtual console with the same number as the function key is then
17selected as the current virtual console and given exclusive use of
18the keyboard and display.
19.Pp
20The console allows entering values that are not physically
21present on the keyboard via a special keysequence.
22To use this facility press and hold down ALT,
23then enter a decimal number from 0-255 via the numerical keypad, then
24release ALT.
25The entered value is then used as the ASCII value for one
26character.
27This way it is possible to enter any ASCII value, not present
28on the keyboard.
29The console driver also includes a history function.
30It is activated by
31pressing the scroll-lock key.
32This holds the display, and enables the cursor
33arrows for scrolling up and down through the last scrolled out lines.
34.Pp
35The keyboard is configurable to suit the individual user and the different
36national layout.
37.Pp
38The keys on the keyboard can have any of the following functions:
39.Pp
40.Bl -tag -width "Modifier Key" -compact
41.It "Normal key"
42Enter the ASCII value associated with the key.
43.It "Function key"
44Enter a string of ASCII values.
45.It "Switch Key"
46Switch virtual console.
47.It "Modifier Key"
48Change the meaning of another key.
49.El
50.Pp
51The keyboard is seen as a number of keys numbered from 1 to n.
52This
53number is often referred to as the "scancode" for a given key.
54The number
55of the key is transmitted as an 8 bit char with bit 7 as 0 when a key is
56pressed, and the number with bit 7 as 1 when released.
57This makes it
58possible to make the mapping of the keys fully configurable.
59.Pp
60The meaning of every key is programmable via the PIO_KEYMAP ioctl call, that
61takes a structure keymap_t as argument.
62The layout of this structure is as
63follows:
64.Bd -literal -offset indent
65		struct keymap {
66			u_short	n_keys;
67			struct key_t {
68				u_char map[NUM_STATES];
69				u_char spcl;
70				u_char flgs;
71			} key[NUM_KEYS];
72		};
73.Ed
74.Pp
75The field n_keys tells the system how many keydefinitions (scancodes)
76follows.
77Each scancode is then specified in the key_t substructure.
78.Pp
79Each scancode can be translated to any of 8 different values, depending
80on the shift, control, and alt state.
81These eight possibilities are
82represented by the map array, as shown below:
83.Bd -literal
84                                                            alt
85 scan                          cntrl          alt    alt   cntrl
86 code     base   shift  cntrl  shift   alt   shift  cntrl  shift
87 map[n]      0       1      2      3     4       5      6      7
88 ----     ------------------------------------------------------
89 0x1E      'a'     'A'   0x01   0x01    'a'    'A'   0x01   0x01
90.Ed
91.Pp
92This is the default mapping for the key labelled 'A' which normally has
93scancode 0x1E.
94The eight states are as shown, giving the 'A' key its
95normal behavior.
96The spcl field is used to give the key "special" treatment, and is
97interpreted as follows.
98Each bit corresponds to one of the states above.
99If the bit is 0 the
100key emits the number defined in the corresponding map[] entry.
101If the bit is 1 the key is "special".
102This means it does not emit
103anything; instead it changes the "state".
104That means it is a shift,
105control, alt, lock, switch-screen, function-key or no-op key.
106The bitmap is backwards i.e.,
1077 for base, 6 for shift etc.
108.Pp
109The flgs field defines if the key should react on caps-lock (1),
110num-lock (2), both (3) or ignore both (0).
111.Pp
112The
113.Xr kbdcontrol 1
114utility is used to load such a description into/outof
115the kernel at runtime.
116This makes it possible to change the key
117assignments at runtime, or more important to get (GIO_KEYMAP ioctl)
118the exact key meanings from the kernel (e.g.\& used by the X server).
119.Pp
120The function keys can be programmed using the SETFKEY ioctl call.
121.Pp
122This ioctl takes an argument of the type fkeyarg_t:
123.Bd -literal -offset indent
124		struct fkeyarg {
125			u_short	keynum;
126			char	keydef[MAXFK];
127			char	flen;
128		};
129.Ed
130.Pp
131The field keynum defines which function key that is programmed.
132The array keydef should contain the new string to be used (MAXFK long),
133and the length should be entered in flen.
134.Pp
135The GETFKEY ioctl call works in a similar manner, except it returns
136the current setting of keynum.
137.Pp
138The function keys are numbered like this:
139.Bd -literal -offset indent
140	F1-F12 			key 1 - 12
141	Shift F1-F12		key 13 - 24
142	Ctrl F1-F12		key 25 - 36
143	Ctrl+shift F1-F12	key 37 - 48
144
145	Home			key 49
146	Up arrow		key 50
147	Page Up			key 51
148	(keypad) -		key 52
149	Left arrow		key 53
150	(keypad) 5              key 54
151	Right arrow		key 55
152	(keypad) +		key 56
153	End			key 57
154	Down arrow		key 58
155	Page down		key 59
156	Insert 			key 60
157	Delete			key 61
158
159	Left window		key 62
160	Right window		key 63
161	Menu			key 64
162.Ed
163.Pp
164The
165.Xr kbdcontrol 1
166utility also allows changing these values at runtime.
167.Sh AUTHORS
168.An S\(/oren Schmidt Aq Mt sos@FreeBSD.org
169