keyboard(HW) 19 June 1992 keyboard(HW) Name keyboard - the PC keyboard Description The PC keyboard is used to enter data, switch screens, and send certain control signals to the computer. The operating system performs terminal emulation on the PC screen and keyboard, and, in doing so, makes use of several particular keys and key combinations. These keys and key combi- nations have special names that are unique to UNIX systems, and may or may not correspond to the keytop labels on your keyboard. These keys are described later. When you press a key, one of the following happens: - An ASCII value is entered. - A string is sent to the computer. - A function is initiated. - The meaning of another key, or keys, is changed. When a key is pressed (a keystroke), the keyboard sends a scancode to the computer. This scancode is interpreted by the keyboard driver. The interpretation of scancodes may be modified so that keys can function differently from their default actions. There are three special occurrences, or keystrokes, which do the follow- ing: - Switch screens - Send signals - Change the value of previous character, characters, or string Switching screens (Multiscreen) To get to the next consecutive screen, enter <Ctrl><PrtSc>. Any active screen may be selected by entering <Alt><Fn> where <Fn> is one of the function keys. <F1> refers to the PC display (/dev/tty01). Signals A signal affects some process or processes. Examples of signals are <Ctrl>d (end of input, exits from shell), <Ctrl>e (quits a process), <Ctrl>s (stop output to the screen), and <Ctrl>q (resume sending output). Typically, characters are mapped to signals using stty(C). Altering values The actual code sent to the keyboard driver can be changed by using cer- tain keys in combination. For example, the <Shift> key changes the ASCII values of the alphanumeric keys. Holding down the <Ctrl> key while pressing another key sends a control code (<Ctrl>d, <Ctrl>s, <Ctrl>q, etc.). Special keys To help you find the special keys, the following table shows which keys on a typical console correspond to UNIX system keys. These are examples and can differ between shells, applications and so forth. _________________________________________________________________________ UNIX Name Keytop Action _________________________________________________________________________ INTR <Del> Stops current action and returns to the shell. This key is also called the RUB OUT or INTERRUPT key. BACKSPACE <- Deletes the first character to the left of the cursor. Note that the ``cursor left'' key also has a left arrow (<-) on its keytop, but you cannot backspace using that key. <Ctrl>d <Ctrl>d Signals the end of input from the keyboard; also exits current shell. <Ctrl>h <Ctrl>h Deletes the first character to the left of the cursor. Also called the ERASE key. <Ctrl>q <Ctrl>q Restarts printing after it has been stopped with <Ctrl>s. <Ctrl>s <Ctrl>s Suspends printing on the screen (does not stop the program). <Ctrl>u <Ctrl>u Deletes all characters on the current line. Also called the KILL key. <Ctrl>\ <Ctrl>\ Quits current command and creates a core file, if allowed. (Recommended for debugging only.) ESCAPE <Esc> Special code for some programs. For example, changes from insert mode to command mode in the vi(C) text edi- tor. RETURN (down-left arrow Terminates a command line and ini- or <Enter>) tiates an action from the shell. Fn Fn Function key n. <F1>-<F12> are unshifted, <F13>-<F24> are shifted <F1>-<F12>, <F25>-<F36> are <Ctrl><F1> through <F12>, and <F37>-<F48> are <Ctrl><Shift><F1> through <F12>. The next Fn keys (<F49>-<F60>) are on the number pad (unshifted): <F49> - '7' <F55> - '6' <F50> - '8' <F56> - '+' <F51> - '9' <F57> - '1' <F52> - '-' <F58> - '2' <F53> - '4' <F59> - '3' <F54> - '5' <F60> - '0' For keys <F61> through <F96>, see /usr/lib/keyboard/strings. These function keys are not available on all keyboards, but you can map other keys to represent them. The keyboard mapping is performed through a structure defined in /usr/include/sys/keyboard.h. Each key can have ten states, generated by holding down the key itself and (optionally) one or more additional keys. The first eight are: Base <Shift> <Ctrl> <Alt> <Ctrl><Shift> <Alt><Shift> <Alt><Ctrl> <Alt><Ctrl><Shift> (Where ``Base'' indicates just the key on its own.) There are two additional states indicated by two special bytes. The first is a ``special state'' byte whose bits indicate whether the key is ``special'' in one or more of the first eight states. The second is one of four characters (C, N, B, O) which indicate how the lock keys affect the particular key. This is discussed further in the next section, ``Scan codes''. Keyboard mode Most keyboards normally are in a PC compatibility mode, though some can be put into a native AT keyboard mode. The UNIX utility kbmode(ADM) can be used to determine if a keyboard supports AT mode, and can also be used to put the keyboard into AT mode until the next time the system is rebooted. A system can also be configured to boot with the keyboard in AT mode with the configure(ADM) utility. Enhanced keyboards are more programmable in AT mode. Also, two <Ctrl> keys and an <Alt> key can be recognized in AT mode. Scan codes The following table describes the default contents of /usr/lib/keyboard/keys. The column headings are: SCAN CODE The scan code generated by the keyboard hardware when a key is pressed. There is no user access to the scan code gen- erated by releasing a key. BASE The normal value of a key press. SHIFT The value of a key press when the <Shift> key is also being held down. LOCK Indicates which lock keys affect that particular key: C indicates <Capslock> N indicates <Numlock> B indicates both O indicates locking is off Keys affected by the lock keys C, B, or N send the shifted value (scan code) of current state when that lock key is on. When the <Shift> key is depressed while a lock key is also on, the key reverts (toggles) to its original state. The other columns are the values of key presses when combinations of the <Ctrl>, <Alt> and <Shift> keys are also held down. All values, except for keywords, are ASCII character values. The key- words refer to the special function keys. _________________________________________________________________________ ALT SCAN CTRL ALT ALT CTRL CODE BASE SHIFT CTRL SHIFT ALT SHIFT CTRL SHIFT LOCK _________________________________________________________________________ 0 nop nop nop nop nop nop nop nop O 1 esc esc nop nop esc esc nop nop O 2 '1' '!' nop nop '1' '!' nop nop O 3 '2' '@' nop nop '2' '@' nop nop O 4 '3' '#' nop nop '3' '#' nop nop O 5 '4' '$' nop nop '4' '$' nop nop O 6 '5' '%' nop nop '5' '%' nop nop O 7 '6' '^' rs rs '6' '^' rs rs O 8 '7' '&' nop nop '7' '&' nop nop O 9 '8' '*' nop nop '8' '*' nop nop O 10 '9' '(' nop nop '9' '(' nop nop O 11 '0' ')' nop nop '0' ')' nop nop O 12 '-' '_' ns ns '-' '_' ns ns O 13 '=' '+' nop nop '=' '+' nop nop O 14 bs bs del del bs bs del del O 15 ht btab nop nop ht btab nop nop O 16 'q' 'Q' dc1 dc1 'q' 'Q' dc1 dc1 C 17 'w' 'W' etb etb 'w' 'W' etb etb C 18 'e' 'E' enq enq 'e' 'E' enq enq C 19 'r' 'R' dc2 dc2 'r' 'R' dc2 dc2 C 20 't' 'T' dc4 dc4 't' 'T' dc4 dc4 C 21 'y' 'Y' em em 'y' 'Y' em em C 22 'u' 'U' nak nak 'u' 'U' nak nak C 23 'i' 'I' ht ht 'i' 'I' ht ht C 24 'o' 'O' si si 'o' 'O' si si C 25 'p' 'P' dle dle 'p' 'P' dle dle C 26 '[' '{' esc esc '[' '{' esc esc O 27 ']' '}' gs gs ']' '}' gs gs O 28 cr cr nl nl cr cr nl nl O 29 ctrl ctrl ctrl ctrl ctrl ctrl ctrl ctrl O 30 'a' 'A' soh soh 'a' 'A' soh soh C 31 's' 'S' dc3 dc3 's' 'S' dc3 dc3 C 32 'd' 'D' eot eot 'd' 'D' eot eot C 33 'f' 'F' ack ack 'f' 'F' ack ack C 34 'g' 'G' bel bel 'g' 'G' bel bel C 35 'h' 'H' bs bs 'h' 'H' bs bs C 36 'j' 'J' nl nl 'j' 'J' nl nl C 37 'k' 'K' vt vt 'k' 'K' vt vt C 38 'l' 'L' np np 'l' 'L' np np C 39 ';' ':' nop nop ';' ':' nop nop O 40 '\'' '"' nop nop '\'' '"' nop nop O 41 '`' '~' nop nop '`' '~' nop nop O 42 lshift lshift lshift lshift lshift lshift lshift lshift O 43 '\\' '|' fs fs '\\' '|' fs fs O 44 'z' 'Z' sub sub 'z' 'Z' sub sub C 45 'x' 'X' can can 'x' 'X' can can C 46 'c' 'C' etx etx 'c' 'C' etx etx C 47 'v' 'V' syn syn 'v' 'V' syn syn C 48 'b' 'B' stx stx 'b' 'B' stx stx C 49 'n' 'N' so so 'n' 'N' so so C 50 'm' 'M' cr cr 'm' 'M' cr cr C 51 ',' '<' nop nop ',' '<' nop nop O 52 '.' '>' nop nop '.' '>' nop nop O 53 '/' '?' nop nop '/' '?' nop nop O 54 rshift rshift rshift rshift rshift rshift rshift rshift O 55 '*' '*' nscr nscr '*' '*' nscr nscr O 56 alt alt alt alt alt alt alt alt O 57 ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' O 58 clock clock clock clock clock clock clock clock O 59 fkey1 fkey13 fkey25 fkey37 scr1 scr11 scr1 scr11 O 60 fkey2 fkey14 fkey26 fkey38 scr2 scr12 scr2 scr12 O 61 fkey3 fkey15 fkey27 fkey39 scr3 scr13 scr3 scr13 O 62 fkey4 fkey16 fkey28 fkey40 scr4 scr14 scr4 scr14 O 63 fkey5 fkey17 fkey29 fkey41 scr5 scr15 scr5 scr15 O 64 fkey6 fkey18 fkey30 fkey42 scr6 scr16 scr6 scr16 O 65 fkey7 fkey19 fkey31 fkey43 scr7 scr7 scr7 scr7 O 66 fkey8 fkey20 fkey32 fkey44 scr8 scr8 scr8 scr8 O 67 fkey9 fkey21 fkey33 fkey45 scr9 scr9 scr9 scr9 O 68 fkey10 fkey22 fkey34 fkey46 scr10 scr10 scr10 scr10 O 69 nlock nlock dc3 dc3 nlock nlock dc3 dc3 O 70 slock slock del del slock slock del del O 71 fkey49 '7' '7' '7' '7' '7' '7' '7' N 72 fkey50 '8' '8' '8' '8' '8' '8' '8' N 73 fkey51 '9' '9' '9' '9' '9' '9' '9' N 74 fkey52 '-' '-' '-' '-' '-' '-' '-' N 75 fkey53 '4' '4' '4' '4' '4' '4' '4' N 76 fkey54 '5' '5' '5' '5' '5' '5' '5' N 77 fkey55 '6' '6' '6' '6' '6' '6' '6' N 78 fkey56 '+' '+' '+' '+' '+' '+' '+' N 79 fkey57 '1' '1' '1' '1' '1' '1' '1' N 80 fkey58 '2' '2' '2' '2' '2' '2' '2' N 81 fkey59 '3' '3' '3' '3' '3' '3' '3' N 82 fkey60 '0' '0' '0' '0' '0' '0' '0' N 83 del '.' del del del del del del N 84 nop nop nop nop nop nop nop nop O 85 fkey11 fkey23 fkey35 fkey47 scr11 scr11 scr11 scr11 O 86 fkey12 fkey24 fkey36 fkey48 scr12 scr12 scr12 scr12 O The following scan codes exist only for keyboards which support, and are in, native AT mode, rather than PC compatibility mode. _________________________________________________________________________ ALT SCAN CTRL ALT ALT CTRL CODE BASE SHIFT CTRL SHIFT ALT SHIFT CTRL SHIFT LOCK _________________________________________________________________________ 87 fkey11 fkey23 fkey35 fkey47 scr11 scr11 scr11 scr11 O 88 fkey12 fkey24 fkey36 fkey48 scr12 scr12 scr12 scr12 O 89 nop nop nop nop nop nop nop nop O 90 nop nop nop nop nop nop nop nop O 91 nop nop nop nop nop nop nop nop O 92 nop nop nop nop nop nop nop nop O 93 nop nop nop nop nop nop nop nop O 94 nop nop nop nop nop nop nop nop O 95 nop nop nop nop nop nop nop nop O 96 fkey50 fkey50 fkey50 fkey50 fkey50 fkey50 fkey50 fkey50 O 97 fkey53 fkey53 fkey53 fkey53 fkey53 fkey53 fkey53 fkey53 O 98 fkey58 fkey58 fkey58 fkey58 fkey58 fkey58 fkey58 fkey58 O 99 fkey55 fkey55 fkey55 fkey55 fkey55 fkey55 fkey55 fkey55 O 100 fkey49 fkey49 fkey49 fkey49 fkey49 fkey49 fkey49 fkey49 O 101 fkey51 fkey51 fkey51 fkey51 fkey51 fkey51 fkey51 fkey51 O 102 fkey57 fkey57 fkey57 fkey57 fkey57 fkey57 fkey57 fkey57 O 103 fkey59 fkey59 fkey59 fkey59 fkey59 fkey59 fkey59 fkey59 O 104 fkey60 fkey60 fkey60 fkey60 fkey60 fkey60 fkey60 fkey60 O 105 del del del del del del del del N 106 fkey54 fkey54 fkey54 fkey54 fkey54 fkey54 fkey54 fkey54 O 107 nop nop nop nop nop nop nop nop O 108 nop nop nop nop nop nop nop nop O 109 nop nop nop nop nop nop nop nop O 110 nop nop nop nop nop nop nop nop O 111 nop nop nop nop nop nop nop nop O 112 nop nop nop nop nop nop nop nop O 113 nop nop nop nop nop nop nop nop O 114 nop nop nop nop nop nop nop nop O 115 nop nop nop nop nop nop nop nop O 116 nop nop nop nop nop nop nop nop O 117 nop nop nop nop nop nop nop nop O 118 nop nop nop nop nop nop nop nop O 119 nop nop nop nop nop nop nop nop O 120 nop nop nop nop nop nop nop nop O 121 nop nop nop nop nop nop nop nop O 122 nop nop nop nop nop nop nop nop O 123 nop nop nop nop nop nop nop nop O 124 nop nop nop nop nop nop nop nop O 125 nop nop nop nop nop nop nop nop O 126 nop nop nop nop nop nop nop nop O 127 nop nop nop nop nop nop nop nop O 128 rctrl rctrl rctrl rctrl rctrl rctrl rctrl rctrl O 129 ralt ralt ralt ralt ralt ralt ralt ralt O 130 fkey60 fkey60 fkey60 fkey60 fkey60 fkey60 fkey60 fkey60 O 131 del del del del del del del del N 132 fkey49 fkey49 fkey49 fkey49 fkey49 fkey49 fkey49 fkey49 O 133 fkey57 fkey57 fkey57 fkey57 fkey57 fkey57 fkey57 fkey57 O 134 fkey51 fkey51 fkey51 fkey51 fkey51 fkey51 fkey51 fkey51 O 135 fkey59 fkey59 fkey59 fkey59 fkey59 fkey59 fkey59 fkey59 O 136 fkey53 fkey53 fkey53 fkey53 fkey53 fkey53 fkey53 fkey53 O 137 fkey55 fkey55 fkey55 fkey55 fkey55 fkey55 fkey55 fkey55 O 138 fkey50 fkey50 fkey50 fkey50 fkey50 fkey50 fkey50 fkey50 O 139 fkey58 fkey58 fkey58 fkey58 fkey58 fkey58 fkey58 fkey58 O 140 '/' nop nop nop '/' nop nop nop O 141 cr cr nl nl cr cr nl nl O The next table lists the ``value'' of each of the special keywords used in /usr/lib/keyboard/keys (and the preceding table). mapkey(M) places a ``value'' in the ioctl(S) buffer during key mapping. The keywords are only used in the scan code file (/usr/lib/keyboard/keys) for readability. _________________________________________________________________________ Name Value Meaning _________________________________________________________________________ nop 0 No operation -- no action from keypress lshift 2 Left-hand shift rshift 3 Right-hand shift clock 4 <Capslock> nlock 5 <Numlock> slock 6 <Scroll lock> alt 7 <Alt> key btab 8 Back tab key -- generates fixed sequence (ESC [ Z) ctrl 9 <Ctrl> key nscr 10 Switch to the next screen scr1 11 Switch to screen #1 ... ... scr16 26 Switch to screen #16 fkey1 27 Function key #1 ... ... fkey96 122 Function key #96 rctl 128* Right <Ctrl> Key ralt 129* Right <Alt> Key * AT-style 101/102 key keyboard only. This table lists names and decimal values that are interchangeable in the mapkey file. Names are used in place of numeric constants to make it easier to read the scan code table. Again, only the decimal values are placed in the ioctl buffer. These are taken from ascii(M). _________________________________________________________________________ Name Value Name Value _________________________________|_______________________________________ nul 0 | dc1 17 soh 1 | dc2 18 stx 2 | dc3 19 etx 3 | dc4 20 eot 4 | nak 21 enq 5 | syn 22 ack 6 | etb 23 bel 7 | can 24 bs 8 | em 25 ht 9 | sub 26 nl 10 | esc 27 vt 11 | fs 28 np 12 | gs 29 cr 13 | rs 30 so 14 | ns 31 si 15 | del 127 dle 16 | Keyboard mapping The PC keyboard is mapped as part of terminal emulation. This kind of mapping is performed only on the computer keyboard, not on remote termi- nals. Use mapkey(M) to change keyboard mapping. To change the mapping for individual channels (multiscreens), use mapchan(M). Keyboard mapping can also be performed using ioctl(S). The syntax is the same as for string key mapping (see previous section). For keyboard mapping, cmd is GIOKEYMAP to display the current map, and PIOKEYMAP puts the prepared buffer into place. String key mapping To map string (function) keys, use the mapstr (see mapkey(M) ) utility. mapstr modifies the string mapping table where function keys are defined. The string mapping table is an array of 512 bytes (typedef strmapt) con- taining null-terminated strings that redefine the function keys. The first null-terminated string is assigned to the first string key, the second string to the second string key, and so on. There is no limit to the length of any particular string as long as the whole table does not exceed 512 bytes, including nulls. Strings are made null by the introduction of extra null characters. The following is a list of default function key values: Default Function Key Values ___________________________________________________________ Key Number Function Key Function ___________________________________________________________ 1 <F1> ESC[M 2 <F2> ESC[N 3 <F3> ESC[O 4 <F4> ESC[P 5 <F5> ESC[Q 6 <F6> ESC[R 7 <F7> ESC[S 8 <F8> ESC[T 9 <F9> ESC[U 10 <F10> ESC[V 11 <F11> ESC[W 12 <F12> ESC[X 13 <Shift><F1> ESC[Y 14 <Shift><F2> ESC[Z 15 <Shift><F3> ESC[a 16 <Shift><F4> ESC[b 17 <Shift><F5> ESC[c 18 <Shift><F6> ESC[d 19 <Shift><F7> ESC[e 20 <Shift><F8> ESC[f 21 <Shift><F9> ESC[g 22 <Shift><F10> ESC[h 23 <Shift><F11> ESC[i 24 <Shift><F12> ESC[j 25 <Ctrl><F1> ESC[k 26 <Ctrl><F2> ESC[l 27 <Ctrl><F3> ESC[m 28 <Ctrl><F4> ESC[n 29 <Ctrl><F5> ESC[o 30 <Ctrl><F6> ESC[p 31 <Ctrl><F7> ESC[q 32 <Ctrl><F8> ESC[r 33 <Ctrl><F9> ESC[s 34 <Ctrl><F10> ESC[t 35 <Ctrl><F11> ESC[u 36 <Ctrl><F12> ESC[v 37 <Ctrl><Shift><F1> ESC[w 38 <Ctrl><Shift><F2> ESC[x 39 <Ctrl><Shift><F3> ESC[y 40 <Ctrl><Shift><F4> ESC[z 41 <Ctrl><Shift><F5> ESC[@ 42 <Ctrl><Shift><F6> ESC[[ 43 <Ctrl><Shift><F7> ESC[\ 44 <Ctrl><Shift><F8> ESC[] 45 <Ctrl><Shift><F9> ESC[^ 46 <Ctrl><Shift><F10> ESC[_ 47 <Ctrl><Shift><F11> ESC[` 48 <Ctrl><Shift><F12> ESC[{ 49 <Home> ESC[H 50 <UpArrow> ESC[A 51 <PgUp> ESC[I 52 <-> - 53 <- ESC[D 54 <5> ESC[E 55 -> ESC[C 56 <+> + 57 <End> ESC[F 58 <DownArrow> ESC[B 59 <PgDn> ESC[G 60 <Ins> ESC[L You can also map string keys using ioctl(S). The syntax is: #include <sys/keyboard.h> ioctl(fd,cmd,buf) int fd, cmd; char *buf; ... Use this for string key mapping where cmd is GIOSTRMAP to display the string mapping table and PIOSTRMAP to put the new string mapping table in place. Files /usr/lib/keyboard/keys /usr/lib/keyboard/strings See also configure(ADM), kbmode(ADM), mapchan(F), mapchan(M), mapkey(M), multiscreen(M), scancode(HW), screen(HW), setkey(C), stty(C)