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