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