libkeymap: Do not dump diacr values if lk_dump_keymap called
[platform/upstream/kbd.git] / doc / kbd.FAQ.sgml
1 <!doctype linuxdoc system>
2
3 <article>
4
5 <title>The Linux keyboard and console HOWTO
6 <author>Andries Brouwer, <tt/aeb@cwi.nl/
7 <date>v2.13, 2002-10-12
8
9 <abstract>This note contains some information about the Linux keyboard
10 and console, and the use of non-ASCII characters.
11 It describes Linux 2.0.
12 <nidx>HOWTOs!keyboard and console</nidx>
13 <nidx>HOWTOs!console and keyboard</nidx>
14 </abstract>
15
16 <toc>
17
18 <sect>Useful programs<p>
19 <nidx>programs!keyboard-related</nidx>
20 <nidx>programs!console-related</nidx>
21 <nidx>keyboard!programs related to</nidx>
22 <nidx>console!programs related to</nidx>
23
24 The following packages contain keyboard or console related programs.
25 <p>
26 <tt/kbd-1.06.tar.gz/ contains <tt/loadkeys/, <tt/dumpkeys/, <tt/showkey/,
27 <tt/setmetamode/, <tt/setleds/, <tt/setfont/, <tt/showconsolefont/,
28 <tt/mapscrn/, <tt/kbd_mode/, <tt/kbdrate/, <tt/loadunimap/, <tt/chvt/,
29 <tt/resizecons/, <tt/deallocvt/, <tt/getkeycodes/, <tt/setkeycodes/.
30 It also contains <tt/openvt/, formerly called <tt/open/.
31 <p>
32 There exists a clone of the kbd package, namely <tt/console-tools/,
33 that contains more or less the same stuff. The latest version,
34 <tt/console-tools-0.3.3/ is roughly up-to-date with <tt/kbd-0.99/.
35 <p>
36 <tt/SVGATextMode-1.10/ contains <tt/SVGATextMode/, a program that
37 obsoletes <tt/resizecons/.
38 <p>
39 <tt/util-linux-2.11/ contains <tt/setterm/.
40 <p>
41 <tt/sh-utils-1.12/ contains <tt/stty/.
42 <p>
43 See also <tt/dynamic-vc-1.2.tar.gz/ and <tt/consd-1.3.tgz/ for
44 programs that exploit the `Keyboard Signal' key. Very primitive
45 versions are <tt/spawn_login/ or <tt/spawn_console/ found in the kbd package.
46 <p>
47 See <htmlurl name="font.tgz" url="http://www.cix.co.uk/~mayday/font.tgz">
48 for a package that handles console fonts.
49 <p>
50 Packages like <tt/recode/ and <tt/konwert-1.8/ allow one to convert
51 between different character encodings.
52 <p>
53
54 The X distribution contains <tt/xmodmap/, <tt/xset/, <tt/kbd_mode/.
55 (See also X386keybd(1) for the situation under XFree86 1.3,
56 and Xserver(1) for the XKEYBOARD extension under X11R6.)
57 A handy interface to <tt/xmodmap/ is <tt/xkeycaps/, see
58 <htmlurl name="http://www.jwz.org/xkeycaps/" url="www.jwz.org/xkeycaps/">.
59
60 <tt/termcap-2.0.8.tar.gz/ contains <tt/termcap/, an old terminal
61 capabilities data base. <tt/ncurses-1.9.9e.tar.gz/ contains the
62 <tt/termlib/ data base which obsoletes <tt/termcap/. (However,
63 there are still many programs using <tt/termcap/.)
64
65 See loadkeys(1), setleds(1) and setmetamode(1) for the codes generated by the
66 various keys and the setting of leds when not under X. Under X, see xmodmap(1)
67 and xset(1).
68
69 See setfont(8) for loading console fonts. Many people will want to
70 load a font like <tt/iso01.f16/ because the default font is the
71 hardware font of the video card, and often is a `Code Page 437' font
72 missing accented characters and other Latin-1 symbols.
73
74 See setterm(1) and kbdrate(8) for properties such as foreground and background
75 colors, screen blanking and character repeat rate when not under X.
76 Under X, see xset(1), also for key click and bell volume.
77
78 The file <tt>/etc/termcap</tt> defines the escape sequences
79 used by many programs addressing the console (or any other terminal).
80 See termcap(5).
81 A more modern version is found in <tt>/usr/lib/terminfo</tt>.
82 See terminfo(5). Terminfo files are compiled
83 by the terminfo compiler <tt>/usr/lib/terminfo/tic</tt>, see tic(1).
84 Their contents can be examined using the program <tt/infocmp/,
85 see infocmp(1).
86
87 The Linux console sequences are documented in console_codes(4).
88
89 The package <tt>funkey</tt> by Rick van Rein provides support
90 for all these new keys modern keyboards have. See
91 <htmlurl url="http://rick.vanrein.org/linux/funkey"
92 name="rick.vanrein.org/linux/funkey">.
93
94 <sect>Keyboard generalities<p>
95 <nidx>keyboard!theory of operation</nidx>
96
97 You press a key, and the keyboard controller sends
98 <htmlurl name="scancodes"
99  url="http://www.win.tue.nl/~aeb/linux/kbd/scancodes.html">
100 to the kernel keyboard driver. Some keyboards can be programmed,
101 but usually the scancodes corresponding to your keys are fixed.
102 The kernel keyboard driver just transmits whatever it receives
103 to the application program when it is in <em>scancode mode</em>,
104 like when <tt/X/ is running. Otherwise, it parses the stream of scancodes
105 into keycodes, corresponding to key press or key release events.
106 (A single key press can generate up to 6 scancodes.)
107 These keycodes are transmitted to the application program when it is
108 in <em>keycode mode</em> (as used, for example, by <tt/showkey/
109 and some X servers).
110 Otherwise, these keycodes are looked up in the keymap, and the character
111 or string found there is transmitted to the application, or the action
112 described there is performed.
113 (For example, if one presses and releases the <tt/a/ key, then the keyboard
114 produces scancodes 0x1e and 0x9e, this is converted to keycodes 30 and 158,
115 and then transmitted as 0141, the ASCII or latin-1 code for `a';
116 if one presses and releases <tt/Delete/, then the keyboard produces scancodes
117 0xe0 0x53 0xe0 0xd3, these are converted to keycodes 111 and 239, and then
118 transmitted as the 4-symbol sequence ESC &lsqb; 3 &tilde;, all assuming
119 a US keyboard and a default keymap. An example of a key combination to which
120 an action is assigned is Ctrl-Alt-Del.)
121 <P>
122 The translation between unusual scancodes and keycodes can be set using the
123 utility <tt/setkeycodes/ - only few people will need it.
124 The translation between keycodes and characters or strings or actions, that is,
125 the keymap, is set using the utilities <tt/loadkeys/ and <tt/setmetamode/.
126 For details, see getkeycodes(8), setkeycodes(8), dumpkeys(1), loadkeys(1),
127 setmetamode(1). The format of the files output by <tt/dumpkeys/ and read
128 by <tt/loadkeys/ is described in keymaps(5).
129 <P>
130 Where it says `transmitted to the application' in the above description,
131 this really means `transmitted to the terminal driver'. That is, further
132 processing is just like that of text that comes in over a serial line.
133 The details of this processing are set by the program <tt/stty/.
134
135 <sect>Console generalities<p>
136 <nidx>console!theory of operation</nidx>
137
138 Conversely, when you output something to the console, it first undergoes
139 the standard tty processing, and then is fed to the console driver.
140 The console driver emulates a VT100, and parses the input in order to
141 recognize VT100 escape sequences (for cursor movement, clear screen, etc.).
142 The characters that are not part of an escape sequence are first converted
143 into Unicode, using one of four mapping tables if the console was not
144 in UTF-8 mode to start with, then looked up in the table describing
145 the correspondence between Unicode values and font positions,
146 and the obtained 8- or 9-bit font indices are then written to video memory,
147 where they cause the display of character shapes found in the video card's
148 character ROM.
149 One can load one's own fonts into character ROM using <tt/setfont/.
150 The obsolete programs <tt/loadunimap/ and <tt/mapscrn/ can be used
151 to manipulate the Unicode map belonging to the font, or the mapping
152 table of the console. More details will be given below.
153
154 There are many consoles (called <it/Virtual Consoles/ or
155 <it/Virtual Terminals/, abbreviated VCs or VTs) that share the same
156 screen. You can use them as independent devices, either to run
157 indendent login sessions, or just to send some output to, perhaps
158 from <tt/top/, or the tail of the system log or so.
159 See below (`Console switching') on how to set them up and
160 switch between them.
161
162
163 <sect>Resetting your terminal<p>
164 <nidx>terminal!resetting</nidx>
165 <nidx>screen!clearing</nidx>
166 <nidx>console!clearing</nidx>
167
168 There is garbage on the screen, or all your keystrokes are echoed
169 as line drawing characters. What to do?
170
171 Many programs will redraw the screen when Ctrl-L is typed. This might
172 help when there is some modem noise or broadcast message on your screen.
173 The command <tt/clear/ will clear the screen.
174
175 The command <tt/reset/ will reset the console driver. This helps when
176 the screen is full of funny graphic characters, and also if it is
177 reduced to the bottom line. If you don't have this command, or if it
178 does something else, make your own by putting the following two lines
179 in an executable file <tt/reset/ in your PATH:
180 <tscreen><verb>
181         #!/bin/sh
182         echo -e \\033c
183 </verb></tscreen>
184 that is, you want to send the two characters ESC c to the console.
185
186 Why is it that the display sometimes gets confused and gives you
187 a 24-line or 1-line screen, instead of the usual 25 lines?
188 Well, the main culprit is the use of <tt/TERM=vt100/ (or some other
189 entry with 24 lines) instead of <tt/TERM=linux/ when logged in remotely.
190 If this happens on <tt>/dev/tty2</tt> then typing
191 <tscreen><verb>
192         % cat > /dev/tty2
193         ^[c
194         ^D
195 </verb></tscreen>
196 on some other VT (where 4 symbols are typed to <tt/cat/: ESC, c, ENTER,
197 Ctrl-D) and refreshing the screen on <tt>/dev/tty2</tt>
198 (perhaps using Ctrl-L) will fix things. Of course the permanent fix
199 is to use the right termcap or terminfo entry.
200 A command that only changes the number of lines is
201 <tscreen><verb>
202         % echo -e "\033[1;25r"
203 </verb></tscreen>
204
205 Why is it that you sometimes get a lot of line-drawing characters,
206 e.g., after catting a binary to the screen?
207 Well, there are various character set changing escape sequences,
208 and by accident your binary might contain some of these.
209 The ESC c is a general reset, a cure for all, but if you know
210 precisely what went wrong you can repair it without resetting
211 other console attributes. For example, after
212 <tscreen><verb>
213         % cat
214         ^N
215         ^D
216 </verb></tscreen>
217 your shell prompt will be all line-drawing characters.
218 Now do (typing blindly)
219 <tscreen><verb>
220         % cat
221         ^O
222         ^D
223 </verb></tscreen>
224 and all is well again. (Three symbols typed to each <tt/cat/:
225 Ctrl-N (or Ctrl-O), ENTER, Ctrl-D.) To understand what is happening,
226 see `The console character sets' below.
227
228 If you loaded some strange font, and want to return to the default,
229 <tscreen><verb>
230         % setfont
231 </verb></tscreen>
232 will do (provided you stored the default font in the default place).
233 If this default font does not contain an embedded Unicode map (and
234 gives the wrong symbols for accented characters), then say
235 <tscreen><verb>
236         % loadunimap
237 </verb></tscreen>
238 For example, if I do
239 <tscreen><verb>
240         % loadkeys de-latin1
241 </verb></tscreen>
242 then I have a German keyboard, and the key left of the Enter key
243 gives me a-umlaut. This works, because the a-umlaut occurs
244 on the CP437 code page and the kernel Unicode map is initialized
245 to CP437, and my video card has a CP437 font built-in.
246 If I now load an ISO 8859-1 font with
247 <tscreen><verb>
248         % setfont iso01.f16
249 </verb></tscreen>
250 then everything still works, because <tt/setfont/ invalidates the kernel
251 Unicode map (if there is no Unicode map attached to the font), and without
252 map the kernel goes directly to the font, and that is precisely correct
253 for an ISO 8859-1 system with <tt/iso01.f16/ font.
254 But going back to the previous font with
255 <tscreen><verb>
256         % setfont
257 </verb></tscreen>
258 gives capital Sigma's instead of a-umlaut - all accented letters
259 are mixed up because also this font has no embedded Unicode map. After
260 <tscreen><verb>
261         % loadunimap
262 </verb></tscreen>
263 which loads the default Unicode map (which is right for the default
264 font) all works correctly again. Usually <tt/loadunimap/ is not
265 invoked directly, but via <tt/setfont/. Thus, the previous two
266 commands may be replaced by
267 <tscreen><verb>
268         % setfont -u def
269 </verb></tscreen>
270 These days most fonts have embedded Unicode maps (often this is
271 indicated by the extension <tt/.psfu/), and none of this nonsense
272 is needed anymore.
273
274 On very old terminals output involving tabs may require a delay,
275 and you have to say
276 <tscreen><verb>
277         % stty tab3
278 </verb></tscreen>
279 (see stty(1)).
280
281 You can change the video mode using <tt/resizecons/ or
282 <tt/SVGATextMode/. Or by rebooting and having "vga=ask"
283 in the LILO configuration file.
284
285 This usually settles the output side.
286
287 On the input side there are many things that might be wrong. If <tt/X/ or
288 <tt/DOOM/ or some other program using raw mode crashed, your keyboard may
289 still be in raw (or mediumraw) mode, and you must give the command
290 <tscreen><verb>
291         % kbd_mode -a
292 </verb></tscreen>
293 or
294 <tscreen><verb>
295         % kbd_mode -u
296 </verb></tscreen>
297 to get back to normal 8-bit or Unicode mode again. Of course in this
298 situation it may be difficult to give commands.
299 (See "How to get out of raw mode" below.)
300
301 If you loaded a bad keymap, then
302 <tscreen><verb>
303         % loadkeys -d
304 </verb></tscreen>
305 loads the default map again, but it may well be difficult to type `-'!
306 An alternative is
307 <tscreen><verb>
308         % loadkeys defkeymap
309 </verb></tscreen>
310 Sometimes even the letters are garbled. It is useful to know that there
311 are four main types of keyboards: QWERTY, QWERTZ, AZERTY and DVORAK.
312 The first three are named after the first six letter keys, and roughly
313 represent the English, German and French speaking countries.
314 Compared to QWERTY, the QWERTZ map interchanges Y and Z.
315 Compared to QWERTY, the AZERTY map interchanges Q and A, W and Z, and has
316 its M right of the L, at the semicolon position.
317 DVORAK has an entirely different letter ordering.
318 There are two types of Turkish keyboard. The so-called `Q'-keyboard
319 has a QWERTY layout, while the `F'-keyboard has an entirely
320 different layout, let us say fgGIod, where G stands for Gbreve
321 and I for dotlessi.
322
323 Matthew Arnison writes: <it>My keyboard got scrambled after vmware died,
324 so that in all X programs Ctrl, Shift, Alt no longer worked.
325 I found a fix to reset the keyboard without stopping X:
326 Run xkeycaps, then choose the correct keyboard then press the button
327 to reset the keyboard.</it>
328
329 <sect1>Keyboard hardware reset<p>
330 <nidx>keyboard!resetting</nidx>
331
332 Things may be wrong on a lower level than Linux knows about.
333 There are at least two distinct lower levels (keyboard and keyboard controller)
334 where one can give the command "keyboard disable" to the keyboard hardware.
335 Keyboards can often be programmed to use one out of three
336 different sets of scancodes.
337 <p>
338 However, I do not know of cases where this turned out to be
339 a problem.
340 <p>
341 Some keyboards have a remapping capability built in.
342 Stormy Henderson (<tt/stormy@Ghost.Net/) writes:
343 `If it's your keyboard accidently being reprogrammed, you can
344 (on a Gateway AnyKey keyboard) press control-alt-suspend_macro
345 to reset the keys to normal.'
346
347 <sect>Delete and Backspace<p>
348 <nidx>delete key!problems with</nidx>
349 <nidx>backspace key!problems with</nidx>
350
351 Getting Delete and Backspace to work just right is nontrivial,
352 especially in a mixed environment, where you talk to console,
353 to <tt/X/, to <tt/bash/, to <tt/emacs/, login remotely, etc.
354 You may have to edit several configuration files to tell all
355 of the programs involved precisely what you want.
356 On the one hand, there is the matter of which keys generate
357 which codes (and how these codes are remapped by e.g. <tt/kermit/
358 or <tt/emacs/), and on the other hand the question of what functions
359 are bound to what codes.
360
361 People often complain `my backspace key does not work', as if this
362 key had a built-in function `delete previous character'.
363 Unfortunately, all this key, or any key, does is producing a code,
364 and one only can hope that the kernel tty driver and
365 all application programs can be configured such that
366 the backspace key indeed does function as a `delete previous character'
367 key.
368
369 Most Unix programs get their tty input via the kernel tty driver
370 in `cooked' mode, and a simple <tt/stty/ command determines the
371 erase character. However, programs like <tt/bash/ and <tt/emacs/
372 and <tt/X/ do their own input handling, and have to be convinced
373 one-by-one to do the right thing.
374
375 <sect1>How to tell Unix what character you want to use to delete the last typed character<p>
376 <nidx>stty!using to set erase character</nidx>
377
378 <tscreen><verb>
379         % stty erase ^?
380 </verb></tscreen>
381 If the character is erased, but in a funny way, then something is
382 wrong with your tty settings. If <tt/echoprt/ is set, then erased characters
383 are enclosed between <tt>&bsol;</tt> and <tt>/</tt>.
384 If <tt/echoe/ is not set, then the erase char is echoed
385 (which is reasonable when it is a printing character, like &num;).
386 Most people will want <tt/stty echoe -echoprt/. Saying <tt/stty sane/
387 will do this and more. Saying <tt/stty -a/ shows your current settings.
388 How come this is not right by default? It is, if you use the right
389 <tt/getty/.
390
391 Note that many programs (like <tt/bash/, <tt/emacs/ etc.) have their own
392 keybindings (defined in <tt>&tilde;/.inputrc</tt>,
393 <tt>&tilde;/.emacs</tt> etc.) and are unaffected by the setting
394 of the erase character.
395
396 The standard Unix tty driver does not recognize a cursor, or keys
397 (like the arrow keys) to move the current position, and hence does not
398 have a command `delete current character' either. But for example
399 you can get <tt/bash/ on the console to recognize the Delete key by putting
400 <tscreen><verb>
401         set editing-mode emacs
402         "\e[3&tilde;":delete-char
403 </verb></tscreen>
404 into <tt>&tilde;/.inputrc</tt>.
405
406 <sect2>`Getty used to do the right thing with DEL and BS but is broken now?'<p>
407 <nidx>getty!problems with BS and DEL</nidx>
408
409 Earlier, the console driver would do BS Space BS
410 (<tt>&bsol;010&bsol;040&bsol;010</tt>)
411 when it got a DEL (<tt>&bsol;177</tt>).
412 Nowadays, DEL's are ignored (as they should be,
413 since the driver emulates a vt100). Get a better getty, i.e.,
414 one that does not output DEL.
415
416 <sect2>`Login behaves differently at the first and second login attempts?'<p>
417 <nidx>login!problems with BS and DEL</nidx>
418
419 At the first attempt, you are talking to <tt/getty/. At the second attempt,
420 you are talking to <tt/login/, a different program.
421
422 <sect1>How to tell Linux what code to generate when a key is pressed<p>
423 <nidx>keyboard!keycode remapping</nidx>
424 <nidx>keycode remapping</nidx>
425
426 On the console, or, more precisely, when not in (MEDIUM)RAW mode, use
427 <tscreen><verb>
428         % loadkeys mykeys.map
429 </verb></tscreen>
430 and under X use
431 <tscreen><verb>
432         % xmodmap mykeys.xmap
433 </verb></tscreen>
434 Note that (since XFree86-2.1) X reads the Linux settings of the keymaps
435 when initialising the X keymap. Although the two systems are not
436 100% compatible, this should mean that in many cases the use of
437 <tt/xmodmap/ has become superfluous.
438
439 For example, suppose that you would like the Backspace key
440 to send a BackSpace (Ctrl-H, octal 010) and the grey Delete key
441 a DEL (octal 0177). Add the following to <tt>/etc/rc.local</tt>
442 (or wherever you keep your local boot-time stuff):
443 <tscreen><verb>
444         /usr/bin/loadkeys << EOF
445         keycode 14 = BackSpace
446         keycode 111 = Delete
447         EOF
448 </verb></tscreen>
449 Note that this will only change the function of these keys
450 when no modifiers are used. (You need to specify a keymaps line
451 to tell which keymaps should be affected if you want to change
452 bindings on more keymaps.)
453 The Linux kernel default lets
454 Ctrl-Backspace generate BackSpace - this is sometimes useful
455 as emergency escape, when you find you can only generate DELs.
456
457 The left Alt key is sometimes called the Meta key, and by
458 default the combinations AltL-X are bound to the symbol MetaX.
459 But what character sequence is MetaX?
460 That is determined (per-tty) by the Meta flag, set by the command
461 <tt/setmetamode/. The two choices are: ESC X or X or-ed with 0200.
462
463 Many distributions have a <tt/loadkeys/ command somewhere in the
464 bootup sequence. For example, one may have the name of the desired
465 keymap in <tt>/etc/sysconfig/keyboard</tt> and the <tt/loadkeys/
466 command that loads it in <tt>/etc/rc.d/init.d/keytable</tt>.
467 Or one may have the actual default keymap in <tt>/etc/default.keytab</tt>
468 and the loadkeys command that loads it in <tt>/etc/rc.d/boot</tt>.
469 Etc. Instead of adding a local modification to the default, one can
470 of course change the default by editing the default keymap or changing
471 the name of the keymap to be loaded at boot time. Note that <tt/loadkeys/
472 itself has default keymap <tt/defkeymap.map/ located somewhere under
473 <tt>/usr/lib/kbd</tt> or <tt>/usr/share/kbd</tt> (just like all other
474 keymaps) and this may not yet be available in single user boot before
475 <tt>/usr</tt> has been mounted.
476
477 <sect2>`How do I get a dvorak keyboard?'<p>
478 <nidx>dvorak keyboard</nidx>
479 The command
480 <tscreen><verb>
481         % loadkeys dvorak
482 </verb></tscreen>
483 will give you a dvorak layout, probably by loading
484 something like <tt>/usr/lib/kbd/keymaps/i386/dvorak/dvorak.map.gz</tt>.
485 Under <tt/X/, put
486 <tscreen><verb>
487         XkbLayout       "dvorak"
488 </verb></tscreen>
489 in <tt>XF86Config</tt>.
490
491 <sect2>`Why doesn't the Backspace key generate BackSpace by default?'<p>
492 <nidx>backspace key!not generating correct keycode</nidx>
493
494 (i) Because the VT100 had a Delete key above the Enter key.
495 <p>
496 (ii) Because Linus decided so.
497
498 <sect1>How to tell X to interchange Delete and Backspace<p>
499 <nidx>X!swapping DEL, BS</nidx>
500 <nidx>xmodmap!using to swap DEL, BS</nidx>
501
502 <tscreen><verb>
503         % xmodmap -e "keysym BackSpace = Delete" -e "keysym Delete = BackSpace"
504 </verb></tscreen>
505 Or, if you just want the Backspace key to generate a BackSpace:
506 <tscreen><verb>
507         % xmodmap -e "keycode 22 = BackSpace"
508 </verb></tscreen>
509 Or, if you just want the Delete key to generate a Delete:
510 <tscreen><verb>
511         % xmodmap -e "keycode 107 = Delete"
512 </verb></tscreen>
513 (but usually this is the default binding already).
514
515 <sect1>How to tell emacs what to do when it receives a Delete or Backspace<p>
516 <nidx>emacs!binding DEL, BS</nidx>
517
518 Put in your <tt/.emacs/ file lines like
519 <tscreen><verb>
520         (global-set-key "\?" 'help-command)
521         (global-set-key "\C-h" 'delete-backward-char)
522 </verb></tscreen>
523 Of course you can bind other commands to other keys in the same way.
524 Note that various major and minor modes redefine keybindings.
525 For example, in incremental search mode one finds the code
526 <tscreen><verb>
527         (define-key map "\177" 'isearch-delete-char)
528         (define-key map "\C-h" 'isearch-mode-help)
529 </verb></tscreen>
530 This means that it may be a bad idea to use the above two
531 global-set-key commands. There are too many places where
532 there are built-in assumptions about Ctrl-H = help and DEL = delete.
533 That doesn't mean that you have to setup keys so that Backspace
534 generates DEL. But if it doesn't then it is easiest to remap
535 them at the lowest possible level in emacs.
536
537 <sect1>How to tell emacs to interchange Delete and Backspace<p>
538 <nidx>emacs!swapping DEL, BS</nidx>
539
540 Put in your <tt/.emacs/ file lines
541 <tscreen><verb>
542         (setq keyboard-translate-table (make-string 128 0))
543         (let ((i 0))
544           (while (< i 128)
545             (aset keyboard-translate-table i i)
546             (setq i (1+ i))))
547         (aset keyboard-translate-table ?\b ?\^?)
548         (aset keyboard-translate-table ?\^? ?\b)
549 </verb></tscreen>
550 Recent versions of emacs have a function <tt/keyboard-translate/
551 and one may simplify the above to
552 <tscreen><verb>
553         (keyboard-translate ?\C-h ?\C-?)
554         (keyboard-translate ?\C-? ?\C-h)
555 </verb></tscreen>
556 Note that under X emacs can distinguish between Ctrl-h and the
557 Backspace key (regardless of what codes these produce on the console),
558 and by default emacs will view the Backspace key as DEL
559 (and do deletion things, as bound to that character, rather than
560 help things, bound to Ctrl-H). One can distinguish Backspace and Delete,
561 e.g. by
562 <tscreen><verb>
563         (global-unset-key [backspace] )
564         (global-set-key [backspace] 'delete-backward-char)
565         (global-unset-key [delete] )
566         (global-set-key [delete] 'delete-char)
567 </verb></tscreen>
568
569 <sect1>How to tell kermit to interchange Delete and Backspace<p>
570 <nidx>kermit!swapping DEL, BS</nidx>
571
572 Put in your <tt/.kermrc/ file the lines
573 <tscreen><verb>
574         set key \127 \8
575         set key \8 \127
576 </verb></tscreen>
577
578 <sect1>How to tell xterm to interchange Delete and Backspace<p>
579 <nidx>xterm!swapping DEL, BS</nidx>
580 <tscreen><verb>
581 XTerm*VT100.Translations:       #override\n\
582         <KeyPress> BackSpace : string(0x7f)\n\
583         <KeyPress> Delete : string(0x08)\n
584 </verb></tscreen>
585
586 <sect1>How to tell xterm about your favourite tty modes<p>
587 <nidx>xterm!setting tty modes for</nidx>
588
589 Normally xterm will inherit the tty modes from its invoker.
590 Under <tt/xdm/, the default erase and kill characters are <tt/#/ and <tt/@/,
591 as in good old Unix Version 6.
592 If you don't like that, you might put something like
593 <tscreen><verb>
594         XTerm*ttymodes: erase ^? kill ^U intr ^C quit ^\ eof ^D \ 
595                         susp ^Z start ^Q stop ^S eol ^@
596 </verb></tscreen>
597 in <tt>/usr/lib/X11/app-defaults/XTerm</tt> or in
598 <tt>&dollar;HOME/.Xresources</tt>, assuming that you have a line
599 <tscreen><verb>
600         xrdb -merge $HOME/.Xresources
601 </verb></tscreen>
602 in your <tt>&dollar;HOME/.xinitrc</tt> or <tt>&dollar;HOME/.xsession</tt>.
603
604 <sect1>How to tell non-Motif X applications that the Del key deletes forward<p>
605 Put
606 <tscreen><verb>
607 *Text.translations:    #override \
608         ~Shift ~Meta <Key>Delete: delete-next-character()
609 </verb></tscreen>
610 into <tt>.Xresources</tt> to make non-Motif X applications such as
611 <tt>xfig</tt>, <tt>xedit</tt>, etc., work correctly. (Daniel T. Cobra)
612
613 <sect1>How to tell xmosaic that the Backspace key generates a DEL<p>
614 <nidx>xmosaic!remapping BS key</nidx>
615 <nidx>Netscape!remapping BS</nidx>
616
617 Putting
618 <tscreen><verb>
619         *XmText.translations: #override\n\
620            <Key>osfDelete: delete-previous-character()
621         *XmTextField.translations: #override\n\
622            <Key>osfDelete: delete-previous-character()
623 </verb></tscreen>
624 in your <tt>&dollar;HOME/.Xdefaults</tt> or
625 <tt>&dollar;HOME/.Xresources</tt> helps.
626 (What file? The file that is fed to <tt>xrdb</tt>, for example
627 in <tt>.xinitrc</tt>.)
628
629 The netscape FAQ, however, says:
630 <verb>
631         Why doesn't my Backspace key work in text fields? 
632         By default, Linux and XFree86 come with the Backspace and Delete keys
633         misconfigured. All Motif programs (including, of course, Netscape
634         Navigator) will malfunction in the same way.
635
636         The Motif spec says that Backspace is supposed to delete the previous
637         character and Delete is supposed to delete the following character.
638         Linux and XFree86 come configured with both the Backspace and Delete
639         keys generating Delete.
640
641         You can fix this by using any one of the xmodmap, xkeycaps, or
642         loadkeys programs to make the key in question generate the BackSpace
643         keysym instead of Delete.
644
645         You can also fix it by having a .motifbind file; see the man page
646         for VirtualBindings(3).
647
648         Note: Don't use the *XmText.translations or *XmTextField.translations
649         resources to attempt to fix this problem. If you do, you will blow
650         away Netscape Navigator's other text-field key bindings.
651 </verb>
652
653 <sect1>A better solution for Motif-using programs, like netscape<p>
654 <nidx>Netscape!remapping BS</nidx>
655 <nidx>Motif!remapping BS</nidx>
656
657 Ted Kandell (<tt/ted@tcg.net/) suggests the following:
658
659 Somewhere in your .profile add the following:
660 <tscreen><verb>
661 stty erase ^H
662 </verb></tscreen>
663 If you are using <tt/bash/, add the following lines to your <tt/.inputrc/:
664 <tscreen><verb>
665 "\C-?": delete-char
666 "\C-h": backward-delete-char
667 </verb></tscreen>
668 Add the following lines to your .xinitrc file:
669 <tscreen><verb>
670 xmodmap <<-EOF
671 keycode 22  =  BackSpace osfBackSpace
672 keycode 107 =  Delete
673 EOF
674
675 # start your window manager here,  for example:
676 #(fvwm) 2>&1 | tee /dev/tty /dev/console
677
678 stty sane
679 stty erase ^H
680 loadmap <<-EOF
681 keycode 14  = BackSpace
682 keycode 111 = Delete
683 EOF
684 </verb></tscreen>
685
686 This will definitely work for a PC 101 or 102 key keyboard
687 with any Linux/XFree86 layout.
688
689 The important part to making Motif apps like Netscape work properly
690 is adding osfBackSpace to keycode 22 in addition to BackSpace.
691
692 Note that there must be spaces on either side of the = sign.
693
694
695 <sect1>What about termcap and terminfo?<p>
696 <nidx>termcap!remapping BS with</nidx>
697 <nidx>terminfo!remapping BS with</nidx>
698
699 When people have problems with backspace, they tend to look at their termcap
700 (or terminfo) entry for the terminal, and indeed, there does exist a kb
701 (or kbs) capability describing the code generated by the Backspace key.
702 However, not many programs use it, so unless you are having problems with one
703 particular program only, probably the fault is elsewhere.
704 Of course it is a good idea anyway to correct your termcap (terminfo) entry.
705 See also below under "The TERM variable".
706
707 <sect1>A complete solution<p>
708 There are many possibilities to get a functioning system.
709 Can't you give one complete set of settings that works?
710 <nidx>delete key!a solution</nidx>
711 <nidx>backspace key!a solution</nidx>
712 <p>
713 One way of getting a setup that works in all contexts
714 is to have the Backspace key generate DEL when on the
715 console (or xterm), and BackSpace when under X.
716 Maybe that is most convenient - there are too many X utilities
717 that expect BackSpace, and emacs on the console or xterm
718 expects DEL, while emacs under X can distinguish [BackSpace]
719 from Ctrl-H and does the right thing.
720 <p>
721 What is needed?
722 No loadkeys changes, since the Backspace key already generates
723 DEL by default.  No stty settings, they are OK by default.
724 No X settings, they are OK by default.
725 One just has to tell xterm that the Backspace key should generate DEL:
726 put 
727 <tscreen><verb>
728 XTerm*VT100.Translations:       #override\n\
729         <KeyPress> BackSpace : string(0x7f)\n\
730 </verb></tscreen>
731 in <tt/.Xresources/, and
732 <tscreen><verb>
733 xrdb -merge .Xresources
734 </verb></tscreen>
735 in <tt/.xinitrc/, and you are settled.
736
737 For a much more extensive discussion of these things, and
738 alternative solutions, see
739 <htmlurl url="http://www.ibb.net/~anne/keyboard.html"
740 name="Anne Baretta's page">.
741
742 <sect>The console character sets<p>
743 <nidx>console character sets</nidx>
744 <nidx>character sets, console</nidx>
745
746 The kernel first tries to figure out what symbol is meant by any given
747 user byte, and next where this symbol is located in the current font.
748
749 The kernel knows about 5 translations of bytes into console-screen symbols.
750 In Unicode (UTF-8) mode, the UTF-8 code is just converted directly into
751 Unicode. The assumption is that almost all symbols one needs are present
752 in Unicode, and for the cases where this does not hold the codes
753 0xf000-0xf1ff are reserved for direct font access.
754 When not in Unicode mode, one of four translation tables is used.
755 The four tables are: a) Latin1 -&gt; Unicode,  b) VT100 graphics -&gt; Unicode,
756 c) PC -&gt; Unicode, d) user-defined.
757
758 There are two character sets, called G0 and G1, and one of them
759 is the current character set. (Initially G0.)
760 Typing Ctrl-N causes G1 to become current, Ctrl-O causes G0 to become current.
761
762 These variables G0 and G1 point at a translation table, and can be changed
763 by the user. Initially they point at tables a) and b), respectively.
764 The sequences ESC ( B and ESC ( 0 and ESC ( U and ESC ( K cause G0 to point
765 at translation table a), b), c) and d), respectively.
766 The sequences ESC ) B and ESC ) 0 and ESC ) U and ESC ) K cause G1 to point
767 at translation table a), b), c) and d), respectively.
768
769 The sequence ESC c causes a terminal reset, which is what you want if the
770 screen is all garbled. The oft-advised <tt/echo &circ;V&circ;O/ will only
771 make G0 current, but there is no guarantee that G0 points at table a).
772 In some distributions there is a program reset(1) that just does
773 <tt>echo &circ;&lsqb;c</tt>.
774 If your termcap entry for the console is correct (and has an entry
775 <tt>:rs=&bsol;Ec:</tt>), then also <tt/setterm -reset/ will work.
776
777 The user-defined mapping table can be set using mapscrn(8).
778 The result of the mapping is that if a symbol c is printed, the symbol
779 <tt>s = map[c]</tt> is sent to the video memory. The bitmap that corresponds to
780 <tt/s/ is found in the character ROM, and can be changed using setfont(8).
781
782 <sect>Console switching<p>
783 <nidx>console!switching</nidx>
784
785 By default, console switching is done using Alt-Fn or Ctrl-Alt-Fn.
786 Under <tt/X/ (or recent versions of <tt/dosemu/), only Ctrl-Alt-Fn works.
787 Many keymaps will allow cyclic walks through all allocated consoles
788 using Alt-RightArrow and Alt-LeftArrow.
789
790 XFree86 1.3 does not know that Alt is down when you switch to the X
791 window. Thus, you cannot switch immediately to some other VT again
792 but have to release Alt first.
793 In the other direction this should work: the kernel always keeps
794 track of the up/down status of all keys. (As far as possible: on some
795 keyboards some keys do not emit a scancode when pressed (e.g.: the PFn
796 keys of a FOCUS 9000) or released (e.g.: the Pause key of many keyboards).)
797
798 XFree86 1.3 saves the fonts loaded in the character ROMs when started,
799 and restores it on a console switch. Thus, the result of <tt/setfont/ on
800 a VT is wiped out when you go to X and back.
801 Using <tt/setfont/ under X will lead to funny results.
802
803 One can change VT under program control using the <tt/chvt/ command.
804
805 <sect1>Changing the number of Virtual Consoles<p>
806 <nidx>console!changing number of</nidx>
807
808 This question still comes up from time to time, but the answer is:
809 you already have enough of them.
810 Since kernel version 1.1.54, there are between 1 and 63 virtual
811 consoles. A new one is created as soon as it is opened. It is
812 removed by the utility <tt/deallocvt/ (but it can be removed only when
813 no processes are associated to it anymore, and no text on it has been
814 selected by programs like <tt/selection/ or <tt/gpm/).
815
816 For older kernels, change the line
817 <tscreen><verb>
818         #define NR_CONSOLES     8
819 </verb></tscreen>
820 in <tt>include/linux/tty.h</tt> (don't increase this number beyond 63),
821 and recompile the kernel.
822
823 If they do not exist yet, create the tty devices with <tt/MAKEDEV/
824 or <tt/mknod tty/N <tt/c 4/ N where N denotes the tty number. For example,
825 <tscreen><verb>
826         for i in 9 10 11 12; do mknod /dev/tty$i c 4 $i; done
827 </verb></tscreen>
828 or, better (since it also takes care of owner and permissions),
829 <tscreen><verb>
830         for i in 9 10 11 12; do /dev/MAKEDEV tty$i; done
831 </verb></tscreen>
832
833 If you want the new VCs to run <tt/getty/, add lines in <tt>/etc/inittab</tt>.
834 (But it is much better to have only two <tt/getty/'s running,
835 and to create more consoles dynamically as the need arises.
836 That way you'll have more memory when you don't use all these consoles,
837 and also more consoles, in case you really need them.
838 Edit <tt>/etc/inittab</tt> and comment out all <tt/getty/'s except
839 for the first two.)
840
841 When the consoles are allocated dynamically, it is usually easiest
842 to have only one or two running <tt/getty/. More are opened by
843 <tt>open -l -s bash</tt>. Unused consoles (without associated processes)
844 are deallocated using <tt/deallocvt/ (formerly <tt/disalloc/).
845 But, you say, I am involved in activities when I suddenly need more
846 consoles, and do not have a bash prompt available to give the <tt/open/
847 command.
848 Fortunately it is possible to create a new console upon a single
849 keystroke, regardless of what is happening at the current console.
850
851 If you have <tt/spawn_login/ from <tt/kbd-1.04.tar.gz/ and you put
852 <tscreen><verb>
853         loadkeys << EOF
854         alt keycode 103 = Spawn_Console
855         EOF
856         spawn_login &
857 </verb></tscreen>
858 in <tt>/etc/rc.local</tt>, then typing Alt-UpArrow will create a fresh VC
859 running <tt/login/ (and switch to it). With <tt/spawn_console &amp;/ instead of
860 <tt/spawn_login &amp;/ you'll have bash running there.
861 See also <tt>open-1.4.tgz</tt> and <tt/dynamic-vc-1.1.tar.gz/.
862
863 What action should be taken upon this Spawn_Console keypress
864 can also be set in <tt>/etc/inittab</tt> under <tt/kbrequest/,
865 if you have a recent <tt/init/. See inittab(5).
866
867 (This action can be something entirely different - I just called
868 the key Spawn_Console because that is what I used it for.
869 When used for other purposes it is less confusing to use
870 its synonym KeyboardSignal.
871 For example, some people like to put the lines
872 <tscreen><verb>
873         kb::kbrequest:/sbin/shutdown -h now
874 </verb></tscreen>
875 in <tt>/etc/inittab</tt>, and
876 <tscreen><verb>
877         control alt keycode 79 = KeyboardSignal
878         control alt keycode 107 = KeyboardSignal
879 </verb></tscreen>
880 in their keymap. Now Ctrl-Alt-End will do a system shutdown.)
881
882 You can only login as "root" on terminals listed in <tt>/etc/securetty</tt>.
883 There exist programs that read terminal settings from files
884 <tt>/etc/ttys</tt> and <tt>/etc/ttytype</tt>. If you have such
885 files, and create additional consoles, then it might be a good idea
886 to also add entries for them in these files.
887
888 <sect>Ctrl-Alt-Del and other special key combinations<p>
889
890 <sect1>Ctrl-Alt-Del (Boot)<p>
891 <nidx>ctrl-alt-del!action taken by</nidx>
892
893 If you press Ctrl-Alt-Del (or whatever key was assigned the keysym Boot by
894 loadkeys) then either the machine reboots immediately (without sync), or
895 <tt/init/ is sent a SIGINT. The former behaviour is the default. The default
896 can be changed by root, using the system call reboot(), see ctrlaltdel(8).
897 Some <tt/init/'s change the default. What happens when <tt/init/ gets SIGINT depends
898 on the version of <tt/init/ used - often it will be determined by the pf entry in
899 <tt>/etc/inittab</tt> (which means that you can run an arbitrary program
900 in this case).
901 In the current kernel Ctrl-AltGr-Del is no longer by default assigned to Boot.
902
903 <sect1>Other combinations<p>
904 <nidx>keyboard!special key combinations</nidx>
905 <nidx>key combinations, special</nidx>
906
907 <verb>
908 Name            Default binding
909 -------------------------------
910 Show_Memory     Shift-Scrollock
911 Show_Registers  AltGr-ScrollLock
912 Show_State      Ctrl-ScrollLock
913 Console_n       Alt-Fn and Ctrl-Alt-Fn  (1 <= n <= 12)
914 Console_{n+12}  AltGr-Fn                (1 <= n <= 12)
915 Incr_Console    Alt-RightArrow
916 Decr_Console    Alt-LeftArrow
917 Last_Console    Alt[Gr]-PrintScreen
918 Scroll_Backward Shift-PageUp
919 Scroll_Forward  Shift-PageDown
920 Caps_On                                 (CapsLock is a toggle; this key sets)
921 Compose         Ctrl-.
922 </verb>
923
924 <sect1>X Combinations<p>
925 <nidx>keyboard!key combinations for X</nidx>
926 <nidx>key combinations, X</nidx>
927 <nidx>X!key combinations for</nidx>
928
929 <verb>
930 Ctrl-Alt-Fn     Switch to VT n
931 Ctrl-Alt-KP+    Next mode
932 Ctrl-Alt-KP-    Previous mode
933 Ctrl-Alt-Backspace      Kill X
934 </verb>
935 On some motherboards, Ctrl-Alt-KP- and Ctrl-Alt-KP+ will be equivalent to
936 pressing the Turbo button. That is, both will produce the scancodes
937 1d 38 4a ca b8 9d and 1d 38 4e ce b8 9d, and both will switch between
938 Turbo (&gt;= 25MHz) and non-Turbo (8 or 12 MHz).
939 (Often these key combinations only function this way when enabled
940 by jumpers on the motherboard.)
941
942 Perry F Nguyen (<tt/pfnguyen@netcom22.netcom.com/) writes:
943 AMI BIOS has a feature that locks up the keyboard and flashes the LED's
944 if the Ctrl-Alt-Backspace combination is pressed while a BIOS password
945 is enabled, until the CMOS/BIOS password is typed in.
946
947 On some SiS based motherboards the combination Ctrl-Alt-Backspace
948 will cause a power off, or puts the machine in power save mode.
949 (Reported for SiS 630 and for SiS645DX.)
950
951 <sect1>Dosemu Combinations<p>
952 <nidx>key combinations!dosemu</nidx>
953 <nidx>dosemu!key combinations for</nidx>
954
955 <verb>
956 Ctrl-Alt-Fn     Switch to VT n (from version 0.50; earlier Alt-Fn)
957 Ctrl-Alt-PgDn   Kill dosemu (when in RAW keyboard mode)
958 (and many other combinations - see the dosemu documentation)
959 </verb>
960
961 <sect1>Composing symbols<p>
962 <nidx>keyboard!composing symbols with</nidx>
963 <nidx>symbols!composing with keyboard</nidx>
964
965 One symbol may be constructed using several keystrokes.
966 <itemize>
967 <item>
968 LeftAlt-press, followed by a decimal number typed on the keypad, followed
969 by LeftAlt-release, yields the symbol with code given by this number.
970 (In Unicode mode this same mechanism, but then with 4 hexadecimal digits,
971 may be used to define a Unicode symbol.)
972 <item>
973 A dead diacritic followed by a symbol, yields that symbol adorned with
974 that diacritic. If the combination is undefined, both keys are taken
975 separately.
976 Which keys are dead diacritics is user-settable; none is by default.
977 Five (since 2.0.25 six) dead diacritics can be defined (using loadkeys(1)):
978 dead_grave, dead_acute, dead_circumflex, dead_tilde, dead_diaeresis
979 (and dead_cedilla).
980 Precisely what this adorning means is also user-settable:
981 dead-diacritic, symbol is equivalent to Compose + diacritic + symbol.
982 <item>
983 Compose followed by two symbols yields a combination symbol. These
984 combinations are user-settable. Today there are 68 combinations
985 defined by default; you can see them by saying "dumpkeys | grep compose".
986 <item>
987 Then there are `Sticky' modifier keys (since 1.3.33). For example,
988 one can type Ctrl-C as SControl, C and Ctrl-Alt-BackSpace as SControl,
989 SAlt, BackSpace.
990 </itemize>
991
992 Note that there are at least four such composition mechanisms:
993 <enum>
994 <item>
995 The Linux keyboard driver mechanism, used in conjunction with loadkeys.
996 <item>
997 The X mechanism - see X386keybd(1), later XFree86kbd(1).
998 Under X11R6: edit <tt>/usr/X11R6/lib/X11/locale/iso8859-1/Compose</tt>.<p>
999 See also Andrew D. Balsa's comments at
1000 <htmlurl url="http://wauug.erols.com/~balsa/linux/deadkeys/index.html"
1001 name="http://wauug.erols.com/~balsa/linux/deadkeys/index.html">.
1002 <item>
1003 The emacs mechanism obtained by loading "iso-insert.el" or
1004 calling `iso-accents-mode'.
1005 <item>
1006 The vim mechanism: insert a composed symbol by pressing Ctrl-K
1007 followed by two symbols. A list of the possible combinations is
1008 obtained by the command <tt>:digraphs</tt>.
1009 </enum>
1010 For X the order of the two symbols is arbitrary: both Compose-,-c and
1011 Compose-c-, yield a c-cedilla; for Linux and emacs only the former sequence
1012 works by default. For X and vim the list of compose combinations is fixed.
1013 Linux and emacs are flexible.
1014 The default lists are somewhat similar, but the details are different.
1015
1016 <sect1>The SysRq key<p>
1017 <nidx>SysRq key</nidx>
1018 In case your kernel was compiled with CONFIG_MAGIC_SYSRQ enabled
1019 (a feature that is present since Linux 2.1.43)
1020 there is a single key (defined in <tt>&lt;linux/keyboard.h&gt;</tt>)
1021 to which special system functions are attached, regardless of the
1022 current keyboard mode. For the PC architecture this special key is,
1023 naturally, the Alt+SysRq key, and any of the two Alt keys will work.
1024 (Note that if CONFIG_MAGIC_SYSRQ was not enabled, the default action
1025 of this key is to return to the previous console.)
1026 <p>
1027 If you press this key, do not release it, and hit another key,
1028 a corresponding action is performed. The action is performed whether
1029 anybody is logged in or not, is root or not. For the details, see
1030 <tt>drivers/char/sysrq.c</tt>. Since this feature is meant only
1031 for kernel hackers, that should suffice. Still, let me add a few
1032 remarks.
1033 <p>
1034 For the key r the keyboard mode is reset to K_XLATE.
1035 For the key k a SAK and console reset is done.
1036 For the key b the machine is rebooted immediately.
1037 (See, not something you want to have enabled on a production machine.)
1038 For the key o the power is turned off (when the machine is capable of that).
1039 For the key s an emergency sync is scheduled.
1040 For the key u an emergency read-only remount is scheduled.
1041 For the keys p,t,m various information is shown
1042 (namely the same information also shown for RAlt,RCtrl,RShift+ScrollLock).
1043 For the keys e,i,l all processes get a SIG_TERM or SIG_KILL, respectively;
1044 for l even the init process is killed.
1045 Digits set the log level. Anything else prints a short summary:
1046 <tt>SysRq: unRaw saK Boot Off Sync Unmount showPc showTasks showMem
1047 loglevel0-8 tErm kIll killalL</tt>.
1048 <p>
1049 Note: These are very dangerous actions! And they do not use your
1050 keymap - indeed, are meant for emergency cases where the state
1051 of your keymap, or even of the entire kernel, is uncertain.
1052 If you use a dvorak keyboard - bad luck! Most other people will
1053 be able to survive: the dangerous letters A,M,Q,W,Y,Z that are
1054 differently placed on English, French and German keyboards, are
1055 not used for actions. (But if your finger slips and you hit L
1056 instead of K - bye bye to your system.)
1057 <p>
1058 In Linux 2.3.13 the possibility to enable/disable SysRq was added.
1059 <tscreen><verb>
1060         echo 0 > /proc/sys/kernel/sysrq
1061 </verb></tscreen>
1062 will disable it (if the kernel was compiled with CONFIG_MAGIC_SYSRQ).
1063
1064 <sect1>Problems<p>
1065 A good keyboard accurately reports multiple key presses.
1066 Especially for people using a keyboard as Braille input device,
1067 where they have to be able to press up to six keys simultaneously,
1068 this is important. Many modern keyboards fail here due to sloppy
1069 design and testing - they misreport or fail in other ways when
1070 four or more keys are pressed simultaneously, sometimes already
1071 when two non-modifier keys are pressed simultaneously.
1072 This affects Linux users a bit: the SysRq key is not a modifier key,
1073 and people report problems using Alt-SysRq-<it>X</it> for various
1074 letters or digits <it>X</it>.
1075 <p>
1076 Long ago a similar problem (`ghosting') was caused by the design
1077 of the scan matrix: when three keys were pressed a fourth was
1078 also seen. That problem was solved by the use of diodes.
1079 Today it is the interface logic that is deficient.
1080
1081 <sect>How to get out of raw mode<p>
1082 <nidx>raw mode, exiting</nidx>
1083
1084 If some program using K_RAW keyboard mode exits without restoring the keyboard
1085 mode to K_XLATE, then it is difficult to do anything - not even Ctrl-Alt-Del
1086 works. However, it is sometimes possible to avoid hitting the reset button.
1087 (And desirable as well: your users may get angry if you kill their Hack game
1088 by rebooting; you might also damage your file system.)
1089 Easy solutions involve logging in from another terminal or another machine
1090 and doing <tt>kbd_mode -a</tt>.
1091 The procedure below assumes that no X is running, that the display is in
1092 text mode, and that you are at your bash prompt, that you are using a US
1093 keyboard layout, and that your interrupt character is Ctrl-C.
1094
1095 Step 1. Start X.
1096 As follows: press 2 (and don't release), press F12 (and don't release)
1097 and immediately afterwards press = . This starts X.
1098   (Explanation: if a key press produces keycode K, then the key release
1099   produces keycode K+128. Probably your shell does not like these high
1100   characters, so we avoid generating them by not releasing any key.
1101   However, we have to be quick, otherwise key repeat starts. The digit 2
1102   produces a Ctrl-C that discards previous junk, the F12 produces an X
1103   and the = a Return.)
1104 Probably your screen will be grey now, since no <tt/.xinitrc/ was specified.
1105 However, Ctrl-Alt-Fn will work and you can go to another VT.
1106 (Ctrl-Alt-Backspace also works, but that exits X, and gets you back into
1107 the previous state, which is not what you want.)
1108
1109 Step 2. Setup to change the keyboard mode.
1110 (For example, by <tt>sleep 5; kbd_mode -a</tt>.)
1111
1112 Step 3. Leave X again.
1113 Alt-Fx (often Alt-F7) brings you back to X, and then Ctrl-Alt-Backspace
1114 exits X. Within 5 seconds your keyboard will be usable again.
1115
1116 If you want to prepare for the occasion, then make
1117 <tt>&bsol;215A&bsol;301</tt> (3 symbols) an alias for <tt/kbd_mode -a/.
1118 Now just hitting = F7 = (3 symbols) will return you to sanity.
1119
1120 <sect>The keyboard LEDs<p>
1121 <nidx>LEDs, keyboard</nidx>
1122 <nidx>keyboard!LEDs on</nidx>
1123
1124 1. There are per-tty keyboard flags:
1125 each VC has its own NumLock, CapsLock, ScrollLock.
1126 By default these keyboard flags are shown in the LEDs.
1127 The usual way to change them is by pressing the corresponding key.
1128 (Side remark: pressing the NumLock key when in application key mode
1129 will not change the NumLock status, but produce an escape sequence.
1130 If you want the NumLock key to always change the Numlock status,
1131 bind it to Bare_Num_Lock.)
1132
1133 2. Next, there are per-tty default keyboard flags,
1134 to initialize the keyboard flags when a reset occurs.
1135 Thus if you want NumLock on all the time, that is possible.
1136 The usual way to change them is by `<tt/setleds -D/ ...'.
1137
1138 3. There is the possibility that the leds do not reflect
1139 the keyboard flags, but something else.
1140 <p>
1141 3A. This something else can be three bits somewhere in the kernel -
1142 which can be used if you want to monitor some hardware or software
1143 status bit(s). If you want this, edit the kernel source to call
1144 <tt/register_leds()/ somewhere.
1145 <p>
1146 3B. This something else can also be whatever some user program wants
1147 to show in the LEDs. Thus, people who like such things can make
1148 nice patterns of lights. If you want this, use the KDSETLED ioctl.
1149
1150 This latter use is not per-tty, but the choice between former
1151 and latter use is per-tty.
1152
1153 Summarizing: Each tty has a flag <tt/kbd->ledmode/.
1154 If this has the value LED_SHOW_FLAGS then the keyboard flags
1155 (NumLock etc.) of that tty are shown.
1156 If this has the value LED_SHOW_MEM then three selected memory
1157 addresses are shown.
1158 If this has the value LED_SHOW_IOCTL then the leds show whatever
1159 value was last assigned to them using the KDSETLED ioctl.
1160
1161 One may add that X uses ioctl's to set the LEDs, but fails
1162 to reset its VT when it exits, so after using X there may
1163 be one VT that is not in the default LED_SHOW_FLAGS state.
1164 This can be fixed by doing `<tt/setleds -L/' on that VT.
1165 See setleds(1).
1166
1167 <sect>The TERM variable<p>
1168 <nidx>TERM environment variable</nidx>
1169 <nidx>environment variables!TERM</nidx>
1170
1171 Many programs use the <tt/TERM/ variable and the database
1172 <tt>/etc/termcap</tt> or <tt>/usr/lib/terminfo/*</tt> to decide
1173 which strings to send for clear screen, move cursor, etc.,
1174 and sometimes also to decide which string is sent
1175 by the users backspace key, function keys etc.
1176 This value is first set by the kernel (for the console).
1177 Usually, this variable is re-set by <tt/getty/, using <tt>/etc/ttytype</tt> or
1178 the argument specified in <tt>/etc/inittab</tt>.
1179 Sometimes, it is also set in <tt>/etc/profile</tt>.
1180
1181 Older systems use <tt/TERM=console/ or <tt/TERM=con80x25/. Newer systems (with
1182 ncurses 1.8.6) use the more specific <tt/TERM=linux/ or <tt/TERM=linux-80x25/.
1183 However, old versions of <tt/setterm/ test for <tt/TERM=con*/ and hence fail
1184 to work with <tt/TERM=linux/.
1185
1186 Since kernel version 1.3.2, the kernel default for the console is
1187 <tt/TERM=linux/.
1188
1189 If you have a termcap without entry for linux, add the word linux
1190 to the entry for the console:
1191 <tscreen><verb>
1192         console|con80x25|linux:\
1193 </verb></tscreen>
1194 and make <tt>/usr/lib/terminfo/l/linux</tt> a copy of or symbolic link to
1195 <tt>/usr/lib/terminfo/c/console</tt>.
1196
1197 <sect1>Terminfo<p>
1198 <nidx>terminfo</nidx>
1199
1200 The terminfo entry for the linux console from ncurses 1.8.6 misses the
1201 entry <tt>kich1=&bsol;E&lsqb;2&tilde;</tt>, needed by some programs.
1202 Edit the file and <tt/tic/ it.
1203
1204 <sect>How to make other programs work with non-ASCII chars<p>
1205 <nidx>non-ASCII characters, using</nidx>
1206
1207 In the bad old days this used to be quite a hassle. Every separate
1208 program had to be convinced individually to leave your bits alone.
1209 Not that all is easy now, but recently a lot of gnu utilities have
1210 learned to react to <tt/LC_CTYPE=iso_8859_1/ or <tt/LC_CTYPE=iso-8859-1/.
1211 Try this first, and if it doesn't help look at the hints below.
1212 Note that in recent versions of libc the routine setlocale() only
1213 works if you have installed the locale files (e.g. in
1214 <tt>/usr/lib/locale</tt>).
1215
1216 NOTE! The above was written years ago. Today locale stuff is a bit different.
1217 Try the command <tt>locale -a</tt> to see which locales are available.
1218 Then use one of these locale names instead of the <tt>iso_8859-1</tt>
1219 mentioned above. For example, <tt>LC_CTYPE=fr_FR.ISO-8859-1</tt> or
1220 <tt/LC_CTYPE=fr_FR@euro</tt>.
1221
1222 NOTE! Some of the below may still be true. Most of it is outdated.
1223 (Please report on what is incorrect today, so that it can be deleted.)
1224
1225 First of all, the 8-th bit should survive the kernel input processing,
1226 so make sure to have <tt/stty cs8 -istrip -parenb/ set.
1227
1228 A. For <tt/emacs/ the details strongly depend on the version.
1229 The information below is for version 19.34. Put lines
1230 <tscreen><verb>
1231         (set-input-mode nil nil 1)
1232         (standard-display-european t)
1233         (require 'iso-syntax)
1234 </verb></tscreen>
1235 into your <tt>&dollar;HOME/.emacs</tt>.
1236 The first line (to be precise: the final 1)
1237 tells <tt/emacs/ not to discard the 8-th bit from input characters.
1238 The second line tells <tt/emacs/ not to display non-ASCII characters
1239 as octal escapes.
1240 The third line specifies the syntactic properties
1241 and case conversion table for the Latin-1 character set
1242 These last two lines are superfluous if you have something like
1243 <tt/LC_CTYPE=ISO-8859-1/ in your environment.
1244 (The variable may also be <tt/LC_ALL/ or even <tt/LANG/.
1245 The value may be anything with a substring `88591' or `8859-1'
1246 or `8859_1'.)
1247 <p>
1248 This is a good start.
1249 On a terminal that cannot display non-ASCII ISO 8859-1 symbols,
1250 the command
1251 <tscreen><verb>
1252         (load-library "iso-ascii")
1253 </verb></tscreen>
1254 will cause accented characters to be displayed comme {,c}a.
1255 If your keymap does not make it easy to produce non-ASCII characters, 
1256 then
1257 <tscreen><verb>
1258         (load-library "iso-transl")
1259 </verb></tscreen>
1260 will make the 2-character sequence Ctrl-X 8 a compose character,
1261 so that the 4-character sequence Ctrl-X 8 , c produces c-cedilla.
1262 Very inconvenient.
1263 <p>
1264 The command
1265 <tscreen><verb>
1266         (iso-accents-mode)
1267 </verb></tscreen>
1268 will toggle ISO-8859-1 accent mode, in which the six
1269 characters ', `, ", &circ;, &tilde;, / are dead keys
1270 modifying the following symbol.
1271 Special combinations: &tilde;c gives a c with cedilla,
1272 &tilde;d gives an Icelandic eth, &tilde;t gives an Icelandic thorn,
1273 "s gives German sharp s, /a gives a with ring,
1274 /e gives an a-e ligature, &tilde;&lt; and &tilde;&gt; give guillemots,
1275 &tilde;! gives an inverted exclamation mark,
1276 &tilde;? gives an inverted question mark, and '' gives an acute accent.
1277 This is the default mapping of accents.
1278 The variable <tt/iso-languages/ is a list of pairs (language name,
1279 accent mapping), and a non-default mapping can be selected using
1280 <tscreen><verb>
1281         (iso-accents-customize LANGUAGE)
1282 </verb></tscreen>
1283 Here LANGUAGE can be one of <tt/"portuguese"/, <tt/"irish"/,
1284 <tt/"french"/, <tt/"latin-2"/, <tt/"latin-1"/.
1285
1286 Since the Linux default compose character is Ctrl-.
1287 it might be convenient to use that everywhere. Try
1288 <tscreen><verb>
1289         (load-library "iso-insert.el")
1290         (define-key global-map [?\C-.] 8859-1-map)
1291 </verb></tscreen>
1292 The latter line will not work under <tt/xterm/, if you use <tt/emacs -nw/,
1293 but in that case you can put
1294 <tscreen><verb>
1295         XTerm*VT100.Translations:       #override\n\
1296               Ctrl <KeyPress> . : string("\0308")
1297 </verb></tscreen>
1298 in your <tt/.Xresources/.)
1299
1300 B. For <tt/less/, put <tt/LESSCHARSET=latin1/ in the environment.
1301 This is also what you need if you see <tt/&bsol;255/ or <tt/&lt;AD&gt;/
1302 in <tt/man/ output: some versions of <tt/less/ will render the soft hyphen
1303 (octal 0255, hex 0xAD) this way when not given permission to output Latin-1.
1304
1305 C. For <tt/ls/, give the option <tt/-N/. (Probably you want to make an alias.)
1306
1307 D. For <tt/bash/ (version 1.13.*), put
1308 <tscreen><verb>
1309         set meta-flag on
1310         set convert-meta off
1311         set output-meta on
1312 </verb></tscreen>
1313 into your <tt>&dollar;HOME/.inputrc</tt>.
1314
1315 E. For <tt/tcsh/, use
1316 <tscreen><verb>
1317         setenv LANG     en_US
1318         setenv LC_CTYPE iso_8859_1
1319 </verb></tscreen>
1320 If you have nls on your system, then the corresponding routines are used.
1321 Otherwise <tt/tcsh/ will assume iso_8859_1, regardless of the values given to
1322 LANG and LC_CTYPE. See the section NATIVE LANGUAGE SYSTEM in tcsh(1).
1323 (The Danish HOWTO says: <tt>setenv LC_CTYPE ISO-8859-1; stty pass8</tt>)
1324
1325 F. For <tt/flex/, give the option <tt/-8/ if the parser it generates must be
1326 able to handle 8-bit input. (Of course it must.)
1327
1328 G. For <tt/elm/, set <tt/displaycharset/ to <tt/ISO-8859-1/.
1329 (Danish HOWTO: <tt/LANG=C/ and <tt/LC_CTYPE=ISO-8859-1/)
1330
1331 H. For programs using curses (such as <tt/lynx/) David Sibley reports:
1332 The regular curses package uses the high-order bit for reverse video mode
1333 (see flag _STANDOUT defined in <tt>/usr/include/curses.h</tt>).  However,
1334 <tt/ncurses/ seems to be 8-bit clean and does display iso-latin-8859-1
1335 correctly.
1336
1337 I. For programs using <tt/groff/ (such as <tt/man/), make sure to use
1338 <tt/-Tlatin1/ instead of <tt/-Tascii/. Old versions of the program <tt/man/
1339 also use <tt/col/, and the next point also applies.
1340
1341 K. For <tt/rlogin/, use option <tt/-8/.
1342
1343 L. For <tt/joe/,
1344 <tt>metalab.unc.edu:/pub/Linux/apps/editors/joe-1.0.8-linux.tar.gz</tt>
1345 is said to work after editing the configuration file. Someone else said:
1346 <tt/joe/: Put the <tt/-asis/ option in <tt>/isr/lib/joerc</tt> in the
1347 first column.
1348
1349 M. For LaTeX: <tt>&bsol;documentstyle&lsqb;isolatin&rsqb;{article}</tt>.
1350 For LaTeX2e: <tt>&bsol;documentclass{article}&bsol;usepackage{isolatin}</tt>
1351 where <tt>isolatin.sty</tt> is available from
1352 <htmlurl url="ftp://ftp.vlsivie.tuwien.ac.at/pub/8bit"
1353 name="ftp.vlsivie.tuwien.ac.at/pub/8bit">.
1354
1355 A nice discussion on the topic of ISO-8859-1 and how to manage 8-bit
1356 characters is contained in the file <tt>grasp.insa-lyon.fr:/pub/faq/fr/accents</tt>
1357 (in French). Another fine discussion (in English) can be found in
1358 <htmlurl
1359 url="ftp://rtfm.mit.edu/pub/usenet-by-group/comp.answers/internationalization/iso-8859-1-charset"
1360 name="rtfm.mit.edu:pub/usenet-by-group/comp.answers/internationalization/iso-8859-1-charset">.
1361
1362 If you need to fix a program that behaves badly with 8-bit characters,
1363 one thing to keep in mind is that if you have a signed char type then
1364 characters may be negative, and using them as an array index will fail.
1365 Several programs can be fixed by judiciously adding (unsigned char) casts.
1366
1367 <sect>X<p>
1368
1369 This FAQ/HOWTO is about the Linux keyboard and console, not about X,
1370 which substitutes its own handling. However, it seems useful to
1371 document some of the Linux keyboard and console related properties
1372 of X.
1373
1374 First of all, when X is started (say using <tt/startx/ or <tt/xinit/)
1375 it opens the first unused console, unless the desired console has been
1376 indicated explicitly, as in <tt/xinit -- vt12/.
1377 Note that this will fail when there is no device file <tt>/dev/tty12</tt>,
1378 but that it will not fail when the indicated console was in use already.
1379 When X finishes, it will return to the original console.
1380 While it is running one can use Ctrl-Alt-Fn to switch to VTn.
1381 <p>
1382 The XFree86 keymap mechanism is much poorer than the Linux mechanism.
1383 For each keycode there are at most 4 symbols defined, namely for the
1384 4 keymaps plain, shift, mod, mod+shift. What is the modifier mod?
1385 It is the one designated by the symbol <tt/Mode_switch/.
1386 For example, the command <tt/xmodmap keys.dk/, where the file
1387 <tt/keys.dk/ contains
1388 <tscreen><verb>
1389 keycode 64 = Mode_switch
1390 keycode 113 = Mode_switch
1391 keycode 38 = a A aring Aring
1392 keycode 26 = e E ae AE
1393 keycode 32 = o O oslash Ooblique
1394 </verb></tscreen>
1395 will make both Alt keys into mod keys, so that Alt+a gives Ã¥ (a-ring), etc.
1396 (Note the illogical naming of oslash and Ooblique.)
1397 Such an <tt/xmodmap/ command can be placed in the <tt/.xinitrc/
1398 shell script that is executed by default when X is started.
1399
1400 <sect1>What precisely does XFree86-2.1 do when it initializes its keymap?<p>
1401 <nidx>keymap!initialization by XFree86</nidx>
1402 <nidx>XFree86!keymap initialization</nidx>
1403
1404 Since version 2.1, XFree86 will initialize its keymap from the Linux keymap,
1405 as far as possible. However, Linux had 16 entries per key (one for each
1406 combination of the Shift, AltGr, Ctrl, Alt modifiers) and presently has
1407 256 entries per key, while X has 4 entries per key (one for each combination
1408 of Shift, Mod), so some information is necessarily lost.
1409
1410 First <tt/X/ reads the <tt/Xconfig/ file, where definitions of the LeftAlt, RightAlt,
1411 RightCtl, ScrollLock keys as Meta, ModeShift, Compose, ModeLock or ScrollLock
1412 might be found - see X386keybd(1), later XFree86kbd(1).
1413
1414 For Mod the LeftAlt key is taken, unless RightCtl was defined as ModeShift or
1415 ModeLock, in which case RightCtl is taken, or RightAlt was so defined, in which
1416 case RightAlt is taken.
1417 This determines how the 4 XFree86 meanings of a key are selected from the 16
1418 Linux meanings.
1419 Note that Linux today does not distinguish by default between the two Ctrl keys
1420 or between the two Shift keys. <tt/X/ does distinguish.
1421
1422 Now the kernel keymap is read and the usually obvious corresponding X
1423 bindings are made. The bindings for the "action keys" Show_Memory, Show_State,
1424 Show_Registers, Last_Console, Console_n, Scroll_Backward, Scroll_Forward,
1425 Caps_On and Boot are ignored, as are the dead diacriticals, and the locks
1426 (except for ShiftLock), and the "ASCII-x" keys.
1427
1428 Next, the definitions in the <tt/Xconfig/ file are used. (Thus, a definition
1429 of Compose in <tt/Xconfig/ will override its value as found in the Linux
1430 keymap.)
1431
1432 What happens to the strings associated with the function keys? Nothing,
1433 X does not have such a concept. (But it is possible to define strings
1434 for function keys in <tt/xterm/ - note however that the window manager gets the
1435 keys first.)
1436
1437 I don't know how to convince <tt/xterm/ that it should use the X keymap
1438 when Alt is pressed; it seems just to look at its resource <tt/eightBitInput/,
1439 and depending on whether that is true or false either set the high order bit
1440 of the character, or generate an additional Escape character
1441 (just like setmetamode(1) does for the console).
1442
1443 <sect>Unusual keys and keyboards<p>
1444 <nidx>keyboard!unusual versions of</nidx>
1445 <nidx>keyboard!non-standard keys on</nidx>
1446
1447 The two keys PrintScrn/SysRq and Pause/Break are special in that they
1448 have two keycodes: the former has keycode 84 when Alt is pressed
1449 simultaneously, and keycode 99 otherwise; the latter has keycode
1450 101 when Ctrl is pressed simultaneously, and keycode 119 otherwise.
1451 (Thus, it makes no sense to bind functions to Alt keycode 99 or
1452 Ctrl keycode 119.) The Pause/Break key is also special in another way:
1453 it does not generate key-up scancodes, but generates the entire
1454 6-scancode sequence on key-down.
1455
1456 If you have strange keys, that do not generate any code under Linux
1457 (or generate messages like "unrecognized scancode"), and your kernel
1458 is 1.1.63 or later, then you can use setkeycodes(1) to tell the kernel
1459 about them. Once they have gotten a keycode from <tt/setkeycodes/,
1460 they can be assigned a function by <tt/loadkeys/.
1461
1462 For example, using <tt/showkey -s/ one sees that Microsoft keyboards
1463 use the scancode sequences (in hexadecimal) e0 5b (left Windows key),
1464 e0 5c (right Windows key), e0 5d (Menu key).
1465 Microsoft Internet keyboard also uses e0 6a (Back), e0 69 (Forward),
1466 e0 68 (Stop), e0 6c (Mail), e0 65 (Search), e0 66 (Favorites),
1467 e0 32 (Web/Home), e0 6b (My Computer), e0 21 (Calculator), e0 5f (Sleep).
1468 Use <tt>dumpkeys</tt> to see what keycodes are still unused.
1469 Typically values like 89-95 and 112-118 and 120-127 are free.
1470 Now
1471 <tscreen><verb>
1472         % setkeycodes e05b 125
1473         % setkeycodes e05c 126
1474         % setkeycodes e05d 127
1475 </verb></tscreen>
1476 assigns keycodes to these scancode sequences, and
1477 <tscreen><verb>
1478         % loadkeys
1479         keycode 125 = Decr_Console
1480         keycode 126 = Incr_Console
1481         keycode 127 = KeyboardSignal
1482         %
1483 </verb></tscreen>
1484 would make these Windows keys go to the previous or next virtual console,
1485 and let the Menu key create a fresh virtual console (in case you have
1486 something like <tt/spawn_console/ running).
1487
1488 <sect1>Funkeys<p>
1489 Many modern keyboards have buttons or keys with labels like
1490 "Vol Up", "Eject" etc. that suggest actions rather than strings.
1491 Of course one can bind shell commands to them, but then they'll
1492 work only when you are at a shell prompt.
1493 Rick van Rein wrote a package funkey consisting of a kernel patch
1494 and a daemon. The kernel patch creates a new character device,
1495 and adds a new key type to indicate which keystrokes should be
1496 sent to this new character device. A daemon can now listen to
1497 the character device, somewhat like <tt>gpm</tt> listens to the
1498 mouse device, and perform the actions indicated in its config file.
1499 See <htmlurl url="http://rick.vanrein.org/linux/funkey"
1500 name="rick.vanrein.org/linux/funkey">.
1501
1502 <sect>Examples of use of loadkeys and xmodmap<p>
1503 <nidx>loadkeys!example using</nidx>
1504 <nidx>xmodmap!example using</nidx>
1505
1506 Switching Caps Lock and Control on the keyboard (assuming you use
1507 keymaps 0-15; check with <tt>dumpkeys | head -1</tt>)
1508 <tscreen><verb>
1509         % loadkeys
1510         keymaps 0-15
1511         keycode 58 = Control
1512         keycode 29 = Caps_Lock
1513         %
1514 </verb></tscreen>
1515 Switching them under X only:
1516 <tscreen><verb>
1517         % xmodmap .xmodmaprc
1518 </verb></tscreen>
1519 where <tt/.xmodmaprc/ contains lines
1520 <tscreen><verb>
1521         remove Lock = Caps_Lock
1522         remove Control = Control_L
1523         keysym Control_L = Caps_Lock
1524         keysym Caps_Lock = Control_L
1525         add Lock = Caps_Lock
1526         add Control = Control_L
1527 </verb></tscreen>
1528 What is this about the key numbering? Backspace is 14 under Linux,
1529 22 under X?  Well, the numbering can best be regarded as arbitrary;
1530 the Linux number of a key can be found using showkey(1), and the
1531 X number using xev(1). Often the X number will be 8 more than the
1532 Linux number.
1533
1534 Something else people like to change are the bindings of the function keys.
1535 Suppose that you want to make F12 produce the string "emacs ".
1536 Then
1537 <tscreen><verb>
1538         % loadkeys
1539         keycode 88 = F12
1540         string F12 = "emacs "
1541         %
1542 </verb></tscreen>
1543 will do this. More explicitly, the procedure is like this:
1544 (i) find the keycodes of the keys to be remapped, using showkey(1).
1545 (ii) save the current keymap, make a copy and edit that:
1546 <tscreen><verb>
1547         % dumpkeys > my_keymap
1548         % cp my_keymap trial_keymap
1549         % emacs trial_keymap
1550         % loadkeys trial_keymap
1551         %
1552 </verb></tscreen>
1553 The format of the table can be guessed by looking at the output
1554 of <tt/dumpkeys/, and is documented in keymaps(5).
1555 When the new keymap functions as desired, you can put an invocation
1556 <tscreen><verb>
1557         loadkeys my_new_keymap
1558 </verb></tscreen>
1559 in <tt>/etc/rc.local</tt> or so, to execute it automatically at boot-up.
1560 Note that changing modifier keys is tricky, and a newbie can easily
1561 get into a situation only an expert can get out of.
1562 <p>
1563 The default directory for keymaps is <tt>/usr/lib/kbd/keymaps</tt>.
1564 The default extension for keymaps is <tt>.map</tt>.
1565 For example, <tt>loadkeys uk</tt> would probably load
1566 <tt>/usr/lib/kbd/keymaps/i386/qwerty/uk.map</tt>.
1567 (With kbd-0.95 and older this would be <tt>/usr/lib/kbd/keytables</tt>
1568 and <tt>/usr/lib/kbd/keytables/uk.map</tt>.)
1569 <p>
1570
1571 (On my machine) <tt>/dev/console</tt> is a symbolic link to <tt>/dev/tty0</tt>,
1572 and the kernel regards <tt>/dev/tty0</tt> as a synonym for the current VT.
1573 XFree86 1.3 changes the owner of <tt>/dev/tty0</tt>, but does not reset this
1574 after finishing. Thus, <tt/loadkeys/ or <tt/dumpkeys/ might fail because
1575 someone else owns <tt>/dev/tty0</tt>;
1576 in such a case you might run X first.
1577 Note that you cannot change keyboard mappings when not at the console
1578 (and not superuser).
1579
1580 <sect1>`I can use only one finger to type with'<p>
1581 <nidx>keyboard!making modifier keys toggle</nidx>
1582
1583 "Can the Shift, Ctrl and Alt keys be made to behave as toggles?"<p>
1584 Yes, after saying
1585 <tscreen><verb>
1586         % loadkeys
1587         keymaps 0-15
1588         keycode 29 = Control_Lock
1589         keycode 42 = Shift_Lock
1590         keycode 56 = Alt_Lock
1591         %
1592 </verb></tscreen>
1593 the left Control, Shift and Alt keys will act as toggles.
1594 The numbers involved are revealed by showkey
1595 (and usually are 29, 97, 42, 54, 56, 100 for left and right control,
1596 shift and alt, respectively), and the functions are
1597 Control_Lock, Shift_Lock, Alt_Lock, ALtGr_Lock.
1598
1599 "What about `sticky' modifier keys?"<p>
1600 Since version 1.3.33, the kernel knows about `sticky' modifier keys.
1601 These act on the next key pressed. So, where one earlier needed
1602 the 3-symbol sequence Shift_Lock a Shift_Lock to type `A', one
1603 can now use the 2-symbol sequence SShift_Lock a.
1604 You can say
1605 <tscreen><verb>
1606         % loadkeys
1607         keymaps 0-15
1608         keycode 54 = SShift
1609         keycode 97 = SCtrl
1610         keycode 100 = SAlt
1611         %
1612 </verb></tscreen>
1613 to make the right Shift, Ctrl, Alt sticky versions of the left ones.
1614 This will allow you to type Ctrl-Alt-Del in three keystrokes with one hand.
1615
1616 The keymaps line in these examples should cover all keymaps you have in use.
1617 You find what keymaps you have in use by
1618 <tscreen><verb>
1619         % dumpkeys | head -1
1620 </verb></tscreen>
1621
1622
1623 <sect1>Sticky keys under <tt/X/<p>
1624 The following text was contributed by Piotr Mitros.
1625
1626 XFree86 supports an accessibility option which allows disabled users
1627 to type single-handed. With sticky keys enabled, the user can hit a
1628 modifier key (ctrl, alt, shift) followed by another key, rather than
1629 having to hold the modifier key while hitting the letter. 
1630
1631 To enable sticky keys, first make sure the xkb extension is enabled
1632 (this is done during initial <tt/X/ server configuration and is usually
1633 enabled by default). Next, run the <tt/X/ server with the <tt/+accessx/
1634 option. If you use <tt/startx/, either run <tt/startx -- +accessx/ or
1635 add <tt/+accessx/ to the serverargs line in the <tt/startx/ script.
1636 If you use <tt/xdm/, add <tt/+accessx/ to the appropriate server line
1637 in <tt>/etc/X11/xdm/Xservers</tt>.
1638
1639 It is also possible to enable <tt/X/ accessibility with some end-user
1640 utilities with a running <tt/X/ server.
1641
1642 Once <tt/X/ accessibility is enabled, press the shift key five times in a
1643 row to enable sticky keys. To disable sticky keys, either press the
1644 shift key five times again, or press a key while holding a modifier
1645 key.
1646
1647 XFree86 also supports Slow Keys, Repeat Keys, Bounce Keys and an
1648 audible bell. <tt/xkbcomp/ can be used to generate a <tt/.xkm/ file
1649 to enable these. The appropriate <tt/xkbcomp/ commands are listed in
1650 <tt>/usr/X11R6/lib/X11/xkb/compat/accessx</tt>.
1651 Unfortunately, the exact process is still undocumented.
1652
1653 <sect>Changing the video mode<p>
1654 <nidx>console!changing video modes</nidx>
1655 <nidx>video modes, changing</nidx>
1656 <nidx>resolution, changing</nidx>
1657
1658 As far as I know there are 6 ways to change resolution:
1659
1660 1. At compile time: change the line
1661 <tscreen><verb>
1662         SVGA_MODE=      -DSVGA_MODE=NORMAL_VGA
1663 </verb></tscreen>
1664 in <tt>/usr/src/linux/Makefile</tt>.
1665
1666 1A. After compilation: use <tt>rdev -v</tt> - a terrible hack, but it exists.
1667
1668 2. At boot time: put <tt>vga=ask</tt> in the lilo config file, and lilo will
1669 ask you what video mode you want. Once you know, put <tt/vga=/mypreference.
1670
1671 3. At run time:
1672 A. Use the <tt/resizecons/ command. (This is a very primitive wrapper around
1673 the VT_RESIZE ioctl.)
1674 B. Use the <tt/SVGATextMode/ command. (This is a less primitive wrapper around
1675 the VT_RESIZE ioctl.)
1676
1677 4. Not "on the console":
1678 Under <tt/dosemu/, or with svgalib etc. you can change the hardware video mode
1679 without the console driver being aware of it. Sometimes this is useful in
1680 getting <tt/resizecons/ or <tt/SVGATextMode/ set up: use <tt/dosemu/ and some
1681 DOS program to get into the desired videomode, dump (say from another VT) the
1682 contents of all video hardware registers, and use that in the initialization
1683 that <tt/resizecons/ and <tt/SVGATextMode/ require.
1684 In some cases where the video mode has gotten into some unusable state,
1685 starting <tt/dosemu/, relying on the BIOS to set up the video mode, and then
1686 killing <tt/dosemu/ (with <tt/kill -9/), is the easiest way to get into shape
1687 again.
1688
1689 <sect1>Instructions for the use of resizecons<p>
1690 <nidx>resizecons program</nidx>
1691
1692 Get svgalib and compile the program <tt/restoretextmode/.
1693 Boot up your machine in all possible video modes
1694 (using <tt/vga=ask/ in the lilo config file), and write
1695 the video hardware register contents to files CxR
1696 (C=cols, R=rows), e.g., 80x25, 132x44, etc.
1697 Put these files in <tt>/usr/lib/kbd/videomodes</tt>.
1698 Now <tt>resizecons 132x44</tt> will change videomode for you
1699 (and send SIGWINCH to all processes that need to know
1700 about this, and load another font if necessary).
1701
1702 At present, <tt/resizecons/ only succeeds when there is memory enough
1703 for both the old and the new consoles at the same time.
1704
1705 <sect>Changing the keyboard repeat rate<p>
1706 <nidx>keyboard!repeat rate, setting</nidx>
1707
1708 At startup, the Linux kernel sets the repeat rate to its maximal value.
1709 For most keyboards this is reasonable, but for some it means that you
1710 can hardly touch a key without getting three copies of the corresponding
1711 symbol. Use the program kbdrate(8) to change the repeat rate, or, if
1712 that doesn't help, edit or remove the section
1713 <code>
1714      ! set the keyboard repeat rate to the max
1715
1716          mov     ax,#0x0305
1717          xor     bx,bx           ! clear bx
1718          int     0x16
1719 </code>
1720 of <tt>/usr/src/linux/&lsqb;arch/i386/&rsqb;boot/setup.S</tt>.
1721
1722 Scott Johnston (<tt/sj@zule.com/) reports: `To program the
1723 repeat rate of a Gateway AnyKey keyboard all one has to do
1724 is press the "Repeat Rate" key, then a function key
1725 F1-F8, then "Repeat Rate" again.  F1 is the slowest possible repeat rate,
1726 and F8 is really fast.  If you somehow manage to mess up your AnyKey
1727 keyboard doing this, simply press Ctrl-Alt-SuspndMacro to reset
1728 your keyboard to factory default settings.'
1729
1730 <sect>Scrolling<p>
1731 <nidx>console!scrolling</nidx>
1732 <nidx>scrolling, console</nidx>
1733
1734 There are two ways to get a screen to scroll.
1735 The first, called `hard scrolling', is to leave the text in
1736 video memory as it is, but change the viewing origin. This is
1737 very fast.
1738 The second, called `soft scrolling', involves moving all screen text
1739 up or down. This is much slower.
1740 The kernel console driver will write text starting at the top of
1741 the video memory, continuing to the bottom, then copy the bottom
1742 part to the top again, and continue, all the time using hard scrolling
1743 to show the right part on the screen.
1744 You can scroll back until the top op the video memory by using
1745 Shift-PageUp (the grey PageUp) and scroll down again using
1746 Shift-PageDown (the grey PageDown), assuming a default keymap.
1747 The amount of scrollback is thus limited to the amount of video memory
1748 you happen to have and you cannot increase this amount.
1749 If you need more scrollback, use some program that
1750 buffers the text, like <tt/less/ or <tt/screen/ - by using
1751 a buffer on disk you can go back to what you did last week.
1752 (One can set the amount of scrollback for <tt/xterm/ by
1753 adding a line like <tt/XTerm*saveLines: 2500/ in <tt/.Xresources/.)
1754
1755 Upon changing virtual consoles, the screen content of the old VT
1756 is copied to kernel memory, and the screen content of the new VT
1757 is copied from kernel memory to video memory. Only the visible screen
1758 is copied, not all of video memory, so switching consoles means
1759 losing the scrollback information.
1760
1761 Sometimes, hard scrolling is undesirable, for example when the hardware
1762 does not have the possibility to change viewing origin. The first
1763 example was a Braille machine that would render the top of video
1764 memory in Braille. There is a kernel boot-time option <tt/no-scroll/
1765 to tell the console driver not to use hard scrolling.
1766 See bootparam(7).
1767
1768 <sect>Screensaving<p>
1769 <nidx>screensaving!controlling</nidx>
1770 <nidx>screen blanking</nidx>
1771
1772 <tt>setterm -blank</tt> <it/nn/ will tell the console driver to blank the
1773 screen after <it/nn/ minutes of inactivity. (With <it/nn/ = 0, screensaving
1774 is turned off. In some old kernels this first took effect after the next
1775 keyboard interrupt.)
1776
1777 The <tt/s/ option of xset(1) will set the X screensaving parameters:
1778 <tt>xset s off</tt> turns off the screensaver,
1779 <tt>xset s 10</tt> blanks the screen after 10 minutes.
1780
1781 The video hardware powersaving modes can be enabled/disabled
1782 using the <tt/setvesablank/ program given in the starting comment of
1783 <tt>/usr/src/linux/drivers/char/vesa_blank.c</tt>.
1784
1785 <sect>Screen dumps<p>
1786 <nidx>console!screenshots, obtaining</nidx>
1787 <nidx>screenshots!obtaining from console</nidx>
1788
1789 <tt>setterm -dump</tt> <it/N/ will dump the contents of the
1790 screen of <tt>/dev/tty</tt><it/N/ to a file <tt/screen.dump/
1791 in the current directory. See setterm(1).
1792
1793 The current contents of the screen of <tt>/dev/tty</tt><it/N/
1794 can be accessed using the device <tt>/dev/vcs</tt><it/N/
1795 (where `vcs' stands for `virtual console screen').
1796 For example, you could have a clock program that displays the
1797 current time in the upper right hand corner of the console screen
1798 (see the program <tt/vcstime/ in <tt/kbd-1.04.tar.gz/).
1799 Just dumping the contents goes with <tt>cat /dev/vcs</tt><it/N/.
1800 These device files <tt>/dev/vcs</tt><it/N/ do not contain
1801 newlines, and do not contain attributes, like colors. From a program
1802 it is usually better to use <tt>/dev/vcsa</tt><it/N/
1803 (`virtual console screen with attributes') instead - it starts with
1804 a header giving the number of rows and columns and the location
1805 of the cursor.
1806 See vcs(4).
1807
1808 <sect>Some properties of the VT100 - application key mode<p>
1809 <nidx>keyboard!VT100 application key mode</nidx>
1810 <nidx>VT100 application key mode</nidx>
1811
1812 : Sometimes my cursor keys or keypad keys produce strange codes?
1813
1814 When the terminal is in application cursor key mode the cursor keys
1815 produce  Esc O x  and otherwise  Esc &lsqb; x  where x is one of A,B,C,D.
1816 Certain programs put the terminal in application cursor key mode;
1817 if you kill them with <tt/kill -9/, or if they crash, then the mode will
1818 not be reset.
1819 <verb>        % echo -e '\033c'  </verb>
1820 resets all properties of the current VC. Just changing the cursor
1821 application key mode is done by
1822 <verb>        % echo -e '\033[?1h' </verb>
1823 (set) and
1824 <verb>        % echo -e '\033[?1l' </verb>
1825 (clear).
1826
1827 When the terminal is in application keypad key mode the keypad keys
1828 produce  Esc O y  and otherwise  Esc &lsqb; z &tilde;  for
1829 certain y and z. Setting application keypad key mode is done by
1830 <verb>        % echo -e '\033=' </verb>
1831 and
1832 <verb>        % echo -e '\033&gt;' </verb>
1833 clears it again.
1834
1835 <sect>Hardware incompatibility<p>
1836 <nidx>keyboard!hardware incompatibilities</nidx>
1837 <nidx>incompatibility!keyboard-related</nidx>
1838
1839 Several people have noticed that they lose typed characters when
1840 a floppy disk is active. It seems that this might be a problem with
1841 Uni-486WB motherboards.
1842
1843 Tjalling Tjalkens (<tt/tjalling@ei.ele.tue.nl/) reports very similar problems
1844 with "a no-brand GMB-486 UNP Vesa motherboard with AMD 486DX2-66 CPU" -
1845 during floppy activity some keystrokes are lost, during floppy tape streamer
1846 (Conner C 250 MQ) activity many keystrokes are lost.
1847
1848 Some people experience sporadic lockups - sometimes associated to
1849 hard disk activity or other I/O.
1850
1851 Ulf Tietz (<tt/ulf@rio70.bln.sni.de/) wrote:
1852 `I have had the same problems, when I had my motherboard tuned too fast.
1853 So I reset all the timings ( CLK, wait statements etc ) to more 
1854 conventional values, and the problems are gone.'
1855
1856 Bill Hogan (<tt/bhogan@crl.com/) wrote:
1857 `If you have an AMI BIOS, you might try setting the Gate A20 emulation
1858 parameter to "chipset" (if you have that option). Whenever I have had
1859 that parameter set to any of the other options on my machine
1860 ("fast", "both", "disabled") I have had frequent keyboard lockups.'
1861
1862 There may be a relation between keyboard problems and the video card in use.
1863
1864 Shawn K. Quinn (<tt/skquinn@wt.net/) wrote:
1865 `I have a Zeos Pantera Pentium-90 that originally came with a Diamond Stealth
1866 64 S3-based video card. Under X I frequently got q's inserted into my text
1867 (how annoying) especially if I typed very fast (during Netrek for instance,
1868 even more annoying because guess what that does :-( ).
1869 Switching to a Creative Labs Graphics Blaster MA202 solved the problem.
1870 I'm assuming the Stealth 64 did something funny with the timings.'
1871
1872 <sect>Copyright<p>
1873 Copyright (c) 1993-2001 by Andries Brouwer.  This document may be
1874 distributed under the terms set forth in the LDP license 
1875 at <htmlurl url="http://metalab.unc.edu/LDP/COPYRIGHT.html"
1876 name="http://metalab.unc.edu/LDP/COPYRIGHT.html"> or
1877 <htmlurl url="ftp://www.win.tue.nl/pub/linux/LDP/COPYRIGHT.txt"
1878 name="ftp://www.win.tue.nl/pub/linux/LDP/COPYRIGHT.txt">.
1879
1880 Additions and corrections are welcome.
1881 Andries Brouwer - <tt/aeb@cwi.nl/
1882
1883 </article>