home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 11 / IOPROG_11.ISO / docs / keyboa~1 < prev    next >
Encoding:
Text File  |  1997-09-02  |  58.1 KB  |  1,390 lines

  1.   The Linux keyboard and console HOWTO
  2.   Andries Brouwer, aeb@cwi.nl
  3.   v2.5, 28 August 1997
  4.  
  5.   This note contains some information about the Linux keyboard and con¡
  6.   sole, and the use of non-ASCII characters.  It describes Linux 2.0.
  7.  
  8.   1.  Useful programs
  9.  
  10.   The following packages contain keyboard or console related programs.
  11.  
  12.   kbd-0.94.tar.gz contains loadkeys, dumpkeys, showkey, setmetamode,
  13.   setleds, setfont, showfont, mapscrn, kbd_mode, loadunimap, chvt,
  14.   resizecons, deallocvt, getkeycodes, setkeycodes.
  15.  
  16.   util-linux-2.6 contains setterm, kbdrate.  (Yes, the more in util-
  17.   linux-2.6 dumps core due to a name conflict. Preserve your old copy,
  18.   or use util-linux-2.5, or change `savetty' to `my_savetty' in more.c.)
  19.  
  20.   sh-utils-1.12 contains stty.
  21.  
  22.   open-1.4.tgz contains open (that should be renamed to openvt). (See
  23.   also dynamic-vc-1.1.tar.gz.)
  24.  
  25.   SVGATextMode-1.6.tar.gz contains SVGATextMode, a program that
  26.   obsoletes resizecons.
  27.  
  28.   The X distribution contains xmodmap, xset, kbd_mode.  (See also
  29.   X386keybd(1) for the situation under XFree86 1.3, and Xserver(1) for
  30.   the XKEYBOARD extension under X11R6.)
  31.  
  32.   termcap-2.0.8.tar.gz contains termcap, an old terminal capabilities
  33.   data base. ncurses-1.9.9e.tar.gz contains the termlib data base which
  34.   obsoletes termcap. (However, there are still many programs using
  35.   termcap.)
  36.  
  37.   See loadkeys(1), setleds(1) and setmetamode(1) for the codes generated
  38.   by the various keys and the setting of leds when not under X. Under X,
  39.   see xmodmap(1) and xset(1).
  40.  
  41.   See setfont(8) for loading console fonts. Many people will want to
  42.   load a font like iso01.f16 because the default font is the hardware
  43.   font of the video card, and often is a `Code Page 437' font missing
  44.   accented characters and other Latin-1 symbols.
  45.  
  46.   See setterm(1) and kbdrate(8) for properties such as foreground and
  47.   background colors, screen blanking and character repeat rate when not
  48.   under X.  Under X, see xset(1), also for key click and bell volume.
  49.  
  50.   The file /etc/termcap defines the escape sequences used by many
  51.   programs addressing the console (or any other terminal).  See
  52.   termcap(5).  A more modern version is found in /usr/lib/terminfo.  See
  53.   terminfo(5). Terminfo files are compiled by the terminfo compiler
  54.   /usr/lib/terminfo/tic, see tic(1).  Their contents can be examined
  55.   using the program infocmp, see infocmp(1).  The Linux console
  56.   sequences are documented in console_codes(4).
  57.  
  58.   2.  Keyboard generalities
  59.  
  60.   You press a key, and the keyboard controller sends scancodes to the
  61.   kernel keyboard driver. Some keyboards can be programmed, but usually
  62.   the scancodes corresponding to your keys are fixed.  The kernel
  63.   keyboard driver just transmits whatever it receives to the application
  64.   program when it is in scancode mode, like when X is running.
  65.   Otherwise, it parses the stream of scancodes into keycodes,
  66.   corresponding to key press or key release events.  (A single key press
  67.   can generate up to 6 scancodes.)  These keycodes are transmitted to
  68.   the application program when it is in keycode mode (as used, for
  69.   example, by showkey).  Otherwise, these keycodes are looked up in the
  70.   keymap, and the character or string found there is transmitted to the
  71.   application, or the action described there is performed.  (For
  72.   example, if one presses and releases the a key, then the keyboard
  73.   produces scancodes 0x1e and 0x9e, this is converted to keycodes 30 and
  74.   158, and then transmitted as 0141, the ASCII or latin-1 code for `a';
  75.   if one presses and releases Delete, then the keyboard produces
  76.   scancodes 0xe0 0x53 0xe0 0xd3, these are converted to keycodes 111 and
  77.   239, and then transmitted as the 4-symbol sequence ESC [ 3 ~, all
  78.   assuming a US keyboard and a default keymap. An example of a key
  79.   combination to which an action is assigned is Ctrl-Alt-Del.)
  80.  
  81.   The translation between unusual scancodes and keycodes can be set
  82.   using the utility setkeycodes - only very few people will need it.
  83.   The translation between keycodes and characters or strings or actions,
  84.   that is, the keymap, is set using the utilities loadkeys and
  85.   setmetamode.  For details, see getkeycodes(8), setkeycodes(8),
  86.   dumpkeys(1), loadkeys(1), setmetamode(1). The format of the files
  87.   output by dumpkeys and read by loadkeys is described in keytables(5).
  88.  
  89.   Where it says `transmitted to the application' in the above
  90.   description, this really means `transmitted to the terminal driver'.
  91.   That is, further processing is just like that of text that comes in
  92.   over a serial line.  The details of this processing are set by the
  93.   program stty.
  94.  
  95.   3.  Console generalities
  96.  
  97.   Conversely, when you output something to the console, it first
  98.   undergoes the standard tty processing, and then is fed to the console
  99.   driver.  The console driver emulates a VT100, and parses the input in
  100.   order to recognize VT100 escape sequences (for cursor movement, clear
  101.   screen, etc.).  The characters that are not part of an escape sequence
  102.   are first converted into Unicode, using one of four mapping tables if
  103.   the console was not in UTF-8 mode to start with, then looked up in the
  104.   table describing the correspondence between Unicode values and font
  105.   positions, and the obtained 8- or 9-bit font indices are then written
  106.   to video memory, where they cause the display of character shapes
  107.   found in the video card's character ROM.  One can load one's own fonts
  108.   into character ROM using setfont, load the corresponding Unicode map
  109.   with loadunimap, and load a user mapping table using mapscrn.  More
  110.   details will be given below.
  111.  
  112.   There are many consoles (called Virtual Consoles or Virtual Terminals,
  113.   abbreviated VCs or VTs) that share the same screen. You can use them
  114.   as independent devices, either to run indendent login sessions, or
  115.   just to send some output to, perhaps from top, or the tail of the
  116.   system log or so.  See below (`Console switching') on how to set them
  117.   up and switch between them.
  118.  
  119.   4.  Resetting your terminal
  120.  
  121.   There is garbage on the screen, or all your keystrokes are echoed as
  122.   line drawing characters. What to do?
  123.  
  124.   Many programs will redraw the screen when ^L is typed. This might help
  125.   when there is some modem noise or broadcast message on your screen.
  126.   The command clear will clear the screen.
  127.  
  128.   The command reset will reset the console driver. This helps when the
  129.   screen is full of funny graphic characters, and also if it is reduced
  130.   to the bottom line. If you don't have this command, or if it does
  131.   something else, make your own by putting the following two lines in an
  132.   executable file reset in your PATH:
  133.  
  134.                #!/bin/sh
  135.                echo -e \\033c
  136.  
  137.   that is, you want to send the two characters ESC c to the console.
  138.  
  139.   Why is it that the display sometimes gets confused and gives you a
  140.   24-line or 1-line screen, instead of the usual 25 lines?  Well, the
  141.   main culprit is the use of TERM=vt100 (or some other entry with 24
  142.   lines) instead of TERM=linux when logged in remotely.  If this happens
  143.   on /dev/tty2 then typing
  144.  
  145.                % cat > /dev/tty2
  146.                ^[c
  147.                ^D
  148.  
  149.   on some other VT (where 4 symbols are typed to cat: ESC, c, ENTER,
  150.   Ctrl-D) and refreshing the screen on /dev/tty2 (perhaps using ^L) will
  151.   fix things. Of course the permanent fix is to use the right termcap or
  152.   terminfo entry.
  153.  
  154.   Why is it that you sometimes get a lot of line-drawing characters,
  155.   e.g., after catting a binary to the screen?  Well, there are various
  156.   character set changing escape sequences, and by accident your binary
  157.   might contain some of these.  The ESC c is a general reset, a cure for
  158.   all, but if you know precisely what went wrong you can repair it
  159.   without resetting other console attributes. For example, after
  160.  
  161.                % cat
  162.                ^N
  163.                ^D
  164.  
  165.   your shell prompt will be all line-drawing characters.  Now do (typing
  166.   blindly)
  167.  
  168.                % cat
  169.                ^O
  170.                ^D
  171.  
  172.   and all is well again. (Three symbols typed to each cat: ^N (or ^O),
  173.   ENTER, Ctrl-D.) To understand what is happening, see `The console
  174.   character sets' below.
  175.  
  176.   If you loaded some strange font, and want to return to the default,
  177.  
  178.                % setfont
  179.  
  180.   will do (provided you stored the default font in the default place).
  181.   If this default font does not contain an embedded Unicode map (and
  182.   gives the wrong symbols for accented characters), then say
  183.  
  184.                % loadunimap
  185.  
  186.   For example, if I do
  187.  
  188.                % loadkeys de-latin1
  189.  
  190.   then I have a German keyboard, and the key left of the Enter key gives
  191.   me a-umlaut. This works, because the a-umlaut occurs on the CP437 code
  192.   page and the kernel Unicode map is initialized to CP437, and my video
  193.   card has a CP437 font built-in.  If I now load an ISO 8859-1 font with
  194.  
  195.                % setfont iso01.f16
  196.  
  197.   then everything still works, because setfont invalidates the kernel
  198.   Unicode map (if there is no Unicode map attached to the font), and
  199.   without map the kernel goes directly to the font, and that is pre¡
  200.   cisely correct for an ISO 8859-1 system with iso01.f16 font.  But
  201.   going back to the previous font with
  202.  
  203.                % setfont
  204.  
  205.   gives capital Sigma's instead of a-umlaut - all accented letters are
  206.   mixed up because also this font has no embedded Unicode map. After
  207.  
  208.                % loadunimap
  209.  
  210.   which loads the default Unicode map (which is right for the default
  211.   font) all works correctly again. Usually loadunimap is not invoked
  212.   directly, but via setfont. Thus, the previous two commands may be
  213.   replaced by
  214.  
  215.           % setfont -u def
  216.  
  217.   The Ethiopian fonts and the lat1u*.psf fonts have embedded Unicode
  218.   code map. Most of the others don't.
  219.  
  220.   On old terminals output involving tabs may require a delay, and you
  221.   have to say
  222.  
  223.                % stty tab3
  224.  
  225.   (see stty(1)).
  226.  
  227.   You can change the video mode using resizecons or SVGATextMode.  This
  228.   usually settles the output side.  On the input side there are many
  229.   things that might be wrong. If X or DOOM or some other program using
  230.   raw mode crashed, your keyboard may still be in raw (or mediumraw)
  231.   mode, and it is difficult to give commands.  (See "How to get out of
  232.   raw mode" below.)  If you loaded a bad keymap, then
  233.  
  234.                % loadkeys -d
  235.  
  236.   loads the default map again, but it may well be difficult to type `-'!
  237.   An alternative is
  238.  
  239.                % loadkeys defkeymap
  240.  
  241.   Sometimes even the letters are garbled. It is useful to know that
  242.   there are four main types of keyboards: QWERTY, QWERTZ, AZERTY and
  243.   DVORAK.  The first three are named after the first six letter keys,
  244.   and roughly represent the English, German and French speaking coun¡
  245.   tries.  Compared to QWERTY, the QWERTZ map interchanges Y and Z.  Com¡
  246.   pared to QWERTY, the AZERTY map interchanges Q and A, W and Z, and has
  247.   its M right of the L, at the semicolon position.  DVORAK has an
  248.   entirely different letter ordering.
  249.  
  250.   4.1.  Keyboard hardware reset
  251.  
  252.   Things may be wrong on a lower level than Linux knows about.  There
  253.   are at least two distinct lower levels (keyboard and keyboard
  254.   controller) where one can give the command "keyboard disable" to the
  255.   keyboard hardware.  Keyboards can often be programmed to use one out
  256.   of three different sets of scancodes.
  257.  
  258.   However, I do not know of cases where this turned out to be a problem.
  259.  
  260.   Some keyboards have a remapping capability built in.  Stormy Henderson
  261.   (stormy@Ghost.Net) writes: `If it's your keyboard accidently being
  262.   reprogrammed, you can (on a Gateway AnyKey keyboard) press control-
  263.   alt-suspend_macro to reset the keys to normal.'
  264.   5.  Delete and Backspace
  265.  
  266.   Getting Delete and Backspace to work just right is nontrivial,
  267.   especially in a mixed environment, where you talk to console, to X, to
  268.   bash, to emacs, login remotely, etc.  You may have to edit several
  269.   configuration files to tell all of the programs involved precisely
  270.   what you want.  On the one hand, there is the matter of which keys
  271.   generate which codes (and how these codes are remapped by e.g. kermit
  272.   or emacs), and on the other hand the question of what functions are
  273.   bound to what codes.
  274.  
  275.   People often complain `my backspace key does not work', as if this key
  276.   had a built-in function `delete previous character'.  Unfortunately,
  277.   all this key, or any key, does is producing a code, and one only can
  278.   hope that the kernel tty driver and all application programs can be
  279.   configured such that the backspace key indeed does function as a
  280.   `delete previous character' key.
  281.  
  282.   Most Unix programs get their tty input via the kernel tty driver in
  283.   `cooked' mode, and a simple stty command determines the erase
  284.   character. However, programs like bash and emacs and X do their own
  285.   input handling, and have to be convinced one-by-one to do the right
  286.   thing.
  287.  
  288.   5.1.  How to tell Unix what character you want to use to delete the
  289.   last typed character
  290.  
  291.                % stty erase ^?
  292.  
  293.   If the character is erased, but in a funny way, then something is
  294.   wrong with your tty settings. If echoprt is set, then erased charac¡
  295.   ters are enclosed between \ and /.  If echoe is not set, then the
  296.   erase char is echoed (which is reasonable when it is a printing char¡
  297.   acter, like #).  Most people will want stty echoe -echoprt. Saying
  298.   stty sane will do this and more. Saying stty -a shows your current
  299.   settings.  How come this is not right by default? It is, if you use
  300.   the right getty.
  301.  
  302.   Note that many programs (like bash, emacs etc.) have their own
  303.   keybindings (defined in ~/.inputrc, ~/.emacs etc.) and are unaffected
  304.   by the setting of the erase character.
  305.  
  306.   The standard Unix tty driver does not recognize a cursor, or keys
  307.   (like the arrow keys) to move the current position, and hence does not
  308.   have a command `delete current character' either. But for example you
  309.   can get bash on the console to recognize the Delete key by putting
  310.  
  311.                set editing-mode emacs
  312.                "\e[3~":delete-char
  313.  
  314.   into ~/.inputrc.
  315.  
  316.   5.1.1.  `Getty used to do the right thing with DEL and BS but is bro¡
  317.   ken now?'
  318.  
  319.   Earlier, the console driver would do BS Space BS (\010\040\010) when
  320.   it got a DEL (\177).  Nowadays, DEL's are ignored (as they should be,
  321.   since the driver emulates a vt100). Get a better getty, i.e., one that
  322.   does not output DEL.
  323.  
  324.   5.1.2.  `Login behaves differently at the first and second login
  325.   attempts?'
  326.  
  327.   At the first attempt, you are talking to getty. At the second attempt,
  328.   you are talking to login, a different program.
  329.  
  330.   5.2.  How to tell Linux what code to generate when a key is pressed
  331.  
  332.   On the console, or, more precisely, when not in (MEDIUM)RAW mode, use
  333.  
  334.                % loadkeys mykeys.map
  335.  
  336.   and under X use
  337.  
  338.                % xmodmap mykeys.xmap
  339.  
  340.   Note that (since XFree86-2.1) X reads the Linux settings of the
  341.   keymaps when initialising the X keymap. Although the two systems are
  342.   not 100% compatible, this should mean that in many cases the use of
  343.   xmodmap has become superfluous.
  344.  
  345.   For example, suppose that you would like the Backspace key to send a
  346.   BackSpace (^H, octal 010) and the grey Delete key a DEL (octal 0177).
  347.   Add the following to /etc/rc.local (or wherever you keep your local
  348.   boot-time stuff):
  349.  
  350.                /usr/bin/loadkeys << EOF
  351.                keycode 14 = BackSpace
  352.                keycode 111 = Delete
  353.                EOF
  354.  
  355.   Note that this will only change the function of these keys when no
  356.   modifiers are used. The Linux kernel default lets Ctrl-Backspace gen¡
  357.   erate BackSpace - this is sometimes useful as emergency escape, when
  358.   you find you can only generate DELs.
  359.  
  360.   The left Alt key is sometimes called the Meta key, and by default the
  361.   combinations AltL-X are bound to the symbol MetaX.  But what character
  362.   sequence is MetaX?  That is determined (per-tty) by the Meta flag, set
  363.   by the command setmetamode. The two choices are: ESC X or X or-ed with
  364.   0200.
  365.   5.2.1.  `Why doesn't the Backspace key generate BackSpace by default?'
  366.  
  367.   (i) Because the VT100 had a Delete key above the Enter key.
  368.  
  369.   (ii) Because Linus decided so.
  370.  
  371.   5.3.  How to tell X to interchange Delete and Backspace
  372.  
  373.                % xmodmap -e "keysym BackSpace = Delete" -e "keysym Delete = BackSpace"
  374.  
  375.   Or, if you just want the Backspace key to generate a BackSpace:
  376.  
  377.                % xmodmap -e "keycode 22 = BackSpace"
  378.  
  379.   Or, if you just want the Delete key to generate a Delete:
  380.  
  381.                % xmodmap -e "keycode 107 = Delete"
  382.  
  383.   (but usually this is the default binding already).
  384.  
  385.   5.4.  How to tell emacs what to do when it receives a Delete or
  386.   Backspace
  387.  
  388.   Put in your .emacs file lines like
  389.  
  390.                (global-set-key "\?" 'help-command)
  391.                (global-set-key "\C-h" 'delete-backward-char)
  392.  
  393.   Of course you can bind other commands to other keys in the same way.
  394.   Note that various major and minor modes redefine keybindings.  For
  395.   example, in incremental search mode one finds the code
  396.  
  397.                (define-key map "\177" 'isearch-delete-char)
  398.                (define-key map "\C-h" 'isearch-mode-help)
  399.  
  400.   This means that it may be a bad idea to use the above two global-set-
  401.   key commands. There are too many places where there are built-in
  402.   assumptions about ^H = help and DEL = delete.  That doesn't mean that
  403.   you have to setup keys so that Backspace generates DEL. But if it
  404.   doesn't then it is easiest to remap them at the lowest possible level
  405.   in emacs.
  406.  
  407.   5.5.  How to tell emacs to interchange Delete and Backspace
  408.  
  409.   Put in your .emacs file lines
  410.  
  411.                (setq keyboard-translate-table (make-string 128 0))
  412.                (let ((i 0))
  413.                  (while (< i 128)
  414.                    (aset keyboard-translate-table i i)
  415.                    (setq i (1+ i))))
  416.                (aset keyboard-translate-table ?\b ?\^?)
  417.                (aset keyboard-translate-table ?\^? ?\b)
  418.  
  419.   Recent versions of emacs have a function keyboard-translate and one
  420.   may simplify the above to
  421.  
  422.                (keyboard-translate ?\C-h ?\C-?)
  423.                (keyboard-translate ?\C-? ?\C-h)
  424.  
  425.   Note that under X emacs can distinguish between Ctrl-h and the
  426.   Backspace key (regardless of what codes these produce on the console),
  427.   and by default emacs will view the Backspace key as DEL (and do dele¡
  428.   tion things, as bound to that character, rather than help things,
  429.   bound to ^H). One can distinguish Backspace and Delete, e.g. by
  430.  
  431.                (global-unset-key [backspace] )
  432.                (global-set-key [backspace] 'delete-backward-char)
  433.                (global-unset-key [delete] )
  434.                (global-set-key [delete] 'delete-char)
  435.  
  436.   5.6.  How to tell kermit to interchange Delete and Backspace
  437.  
  438.   Put in your .kermrc file the lines
  439.  
  440.                set key \127 \8
  441.                set key \8 \127
  442.  
  443.   5.7.  How to tell xterm about your favourite tty modes
  444.  
  445.   Normally xterm will inherit the tty modes from its invoker.  Under
  446.   xdm, the default erase and kill characters are # and @, as in good old
  447.   Unix Version 6.  If you don't like that, you might put something like
  448.  
  449.           XTerm*ttymodes: erase ^? kill ^U intr ^C quit ^\ eof ^D \
  450.                           susp ^Z start ^Q stop ^S eol ^@
  451.  
  452.   in /usr/lib/X11/app-defaults/XTerm or in $HOME/.Xresources, assuming
  453.   that you have a line
  454.  
  455.                xrdb $HOME/.Xresources
  456.  
  457.   in your $HOME/.xinitrc.
  458.  
  459.   5.8.  How to tell xmosaic that the Backspace key generates a DEL
  460.  
  461.   Putting
  462.  
  463.                *XmText.translations: #override\n\
  464.                   <Key>osfDelete: delete-previous-character()
  465.                *XmTextField.translations: #override\n\
  466.                   <Key>osfDelete: delete-previous-character()
  467.  
  468.   in your $HOME/.Xresources helps.
  469.  
  470.   The netscape FAQ, however, says:
  471.  
  472.           Why doesn't my Backspace key work in text fields?
  473.           By default, Linux and XFree86 come with the Backspace and Delete keys
  474.           misconfigured. All Motif programs (including, of course, Netscape
  475.           Navigator) will malfunction in the same way.
  476.  
  477.           The Motif spec says that Backspace is supposed to delete the previous
  478.           character and Delete is supposed to delete the following character.
  479.           Linux and XFree86 come configured with both the Backspace and Delete
  480.           keys generating Delete.
  481.  
  482.           You can fix this by using any one of the xmodmap, xkeycaps, or
  483.           loadkeys programs to make the key in question generate the BackSpace
  484.           keysym instead of Delete.
  485.  
  486.           You can also fix it by having a .motifbind file; see the man page
  487.           for VirtualBindings(3).
  488.  
  489.           Note: Don't use the *XmText.translations or *XmTextField.translations
  490.           resources to attempt to fix this problem. If you do, you will blow
  491.           away Netscape Navigator's other text-field key bindings.
  492.  
  493.   5.9.  A better solution for Motif-using programs, like netscape
  494.  
  495.   Ted Kandell (ted@tcg.net) suggests the following:
  496.  
  497.   Somewhere in your .profile add the following:
  498.  
  499.        stty erase ^H
  500.  
  501.   If you are using bash, add the following lines to your .inputrc:
  502.  
  503.        "\C-?": delete-char
  504.        "\C-h": backward-delete-char
  505.  
  506.   Add the following lines to your .xinitrc file:
  507.  
  508.        xmodmap <<-EOF
  509.        keycode 22  =  BackSpace osfBackSpace
  510.        keycode 107 =  Delete
  511.        EOF
  512.  
  513.        # start your window manager here,  for example:
  514.        #(fvwm) 2>&1 | tee /dev/tty /dev/console
  515.  
  516.        stty sane
  517.        stty erase ^H
  518.        loadmap <<-EOF
  519.        keycode 14  = BackSpace
  520.        keycode 111 = Delete
  521.        EOF
  522.  
  523.   This will definitely work for a PC 101 or 102 key keyboard with any
  524.   Linux/XFree86 layout.
  525.  
  526.   The important part to making Motif apps like Netscape work properly is
  527.   adding osfBackSpace to keycode 22 in addition to BackSpace.
  528.  
  529.   Note that there must be spaces on either side of the = sign.
  530.  
  531.   5.10.  What about termcap and terminfo?
  532.  
  533.   When people have problems with backspace, they tend to look at their
  534.   termcap (or terminfo) entry for the terminal, and indeed, there does
  535.   exist a kb (or kbs) capability describing the code generated by the
  536.   Backspace key.  However, not many programs use it, so unless you are
  537.   having problems with one particular program only, probably the fault
  538.   is elsewhere.  Of course it is a good idea anyway to correct your
  539.   termcap (terminfo) entry.  See also below under "The TERM variable".
  540.  
  541.   6.  The console character sets
  542.  
  543.   The kernel first tries to figure out what symbol is meant by any given
  544.   user byte, and next where this symbol is located in the current font.
  545.  
  546.   The kernel knows about 5 translations of bytes into console-screen
  547.   symbols.  In Unicode (UTF-8) mode, the UTF-8 code is just converted
  548.   directly into Unicode. The assumption is that almost all symbols one
  549.   needs are present in Unicode, and for the cases where this does not
  550.   hold the codes 0xff** are reserved for direct font access.  When not
  551.   in Unicode mode, one of four translation tables is used.  The four
  552.   tables are: a) Latin1 -> Unicode,  b) VT100 graphics -> Unicode, c) PC
  553.   -> Unicode, d) user-defined.
  554.  
  555.   There are two character sets, called G0 and G1, and one of them is the
  556.   current character set. (Initially G0.)  Typing ^N causes G1 to become
  557.   current, ^O causes G0 to become current.
  558.  
  559.   These variables G0 and G1 point at a translation table, and can be
  560.   changed by the user. Initially they point at tables a) and b),
  561.   respectively.  The sequences ESC ( B and ESC ( 0 and ESC ( U and ESC (
  562.   K cause G0 to point at translation table a), b), c) and d),
  563.   respectively.  The sequences ESC ) B and ESC ) 0 and ESC ) U and ESC )
  564.   K cause G1 to point at translation table a), b), c) and d),
  565.   respectively.
  566.  
  567.   The sequence ESC c causes a terminal reset, which is what you want if
  568.   the screen is all garbled. The oft-advised echo ^V^O will only make G0
  569.   current, but there is no guarantee that G0 points at table a).  In
  570.   some distributions there is a program reset(1) that just does echo
  571.   ^[c.  If your termcap entry for the console is correct (and has an
  572.   entry :rs=\Ec:), then also setterm -reset will work.
  573.  
  574.   The user-defined mapping table can be set using mapscrn(8).  The
  575.   result of the mapping is that if a symbol c is printed, the symbol s =
  576.   map[c] is sent to the video memory. The bitmap that corresponds to s
  577.   is found in the character ROM, and can be changed using setfont(8).
  578.  
  579.   7.  Console switching
  580.  
  581.   By default, console switching is done using Alt-Fn or Ctrl-Alt-Fn.
  582.   Under X (or recent versions of dosemu), only Ctrl-Alt-Fn works.  Many
  583.   keymaps will allow cyclic walks through all allocated consoles using
  584.   Alt-RightArrow and Alt-LeftArrow.
  585.  
  586.   XFree86 1.3 does not know that Alt is down when you switch to the X
  587.   window. Thus, you cannot switch immediately to some other VT again but
  588.   have to release Alt first.  In the other direction this should work:
  589.   the kernel always keeps track of the up/down status of all keys. (As
  590.   far as possible: on some keyboards some keys do not emit a scancode
  591.   when pressed (e.g.: the PFn keys of a FOCUS 9000) or released (e.g.:
  592.   the Pause key of many keyboards).)
  593.  
  594.   XFree86 1.3 saves the fonts loaded in the character ROMs when started,
  595.   and restores it on a console switch. Thus, the result of setfont on a
  596.   VT is wiped out when you go to X and back.  Using setfont under X will
  597.   lead to funny results.
  598.  
  599.   One can change VT under program control using the chvt command.
  600.  
  601.   7.1.  Changing the number of Virtual Consoles
  602.  
  603.   This question still comes up from time to time, but the answer is: you
  604.   already have enough of them.  Since kernel version 1.1.54, there are
  605.   between 1 and 63 virtual consoles. A new one is created as soon as it
  606.   is opened. It is removed by the utility deallocvt (but it can be
  607.   removed only when no processes are associated to it anymore, and no
  608.   text on it has been selected by programs like selection or gpm).
  609.  
  610.   For older kernels, change the line
  611.  
  612.                #define NR_CONSOLES     8
  613.  
  614.   in include/linux/tty.h (don't increase this number beyond 63), and
  615.   recompile the kernel.
  616.  
  617.   If they do not exist yet, create the tty devices with MAKEDEV or mknod
  618.   ttyN c 4 N where N denotes the tty number. For example,
  619.  
  620.                for i in 9 10 11 12; do mknod /dev/tty$i c 4 $i; done
  621.  
  622.   or, better (since it also takes care of owner and permissions),
  623.  
  624.                for i in 9 10 11 12; do /dev/MAKEDEV tty$i; done
  625.  
  626.   If you want the new VCs to run getty, add lines in /etc/inittab.  (But
  627.   it is much better to have only two getty's running, and to create more
  628.   consoles dynamically as the need arises.  That way you'll have more
  629.   memory when you don't use all these consoles, and also more consoles,
  630.   in case you really need them.  Edit /etc/inittab and comment out all
  631.   getty's except for the first two.)
  632.  
  633.   When the consoles are allocated dynamically, it is usually easiest to
  634.   have only one or two running getty. More are opened by open -l -s
  635.   bash. Unused consoles (without associated processes) are deallocated
  636.   using deallocvt (formerly disalloc).  But, you say, I am involved in
  637.   activities when I suddenly need more consoles, and do not have a bash
  638.   prompt available to give the open command.  Fortunately it is possible
  639.   to create a new console upon a single keystroke, regardless of what is
  640.   happening at the current console.
  641.  
  642.   If you have spawn_login from kbd-0.94.tar.gz and you put
  643.  
  644.                loadkeys << EOF
  645.                alt keycode 103 = Spawn_Console
  646.                EOF
  647.                spawn_login &
  648.  
  649.   in /etc/rc.local, then typing Alt-UpArrow will create a fresh VC run¡
  650.   ning login (and switch to it). With spawn_console & instead of
  651.   spawn_login & you'll have bash running there.  See also open-1.4.tgz
  652.   and dynamic-vc-1.1.tar.gz.
  653.  
  654.   What action should be taken upon this Spawn_Console keypress can also
  655.   be set in /etc/inittab under kbrequest, if you have a recent init. See
  656.   inittab(5).  (The action can be something entirely different - I just
  657.   called the key Spawn_Console because that is what I used it for.)
  658.   You can only login as "root" on terminals listed in /etc/securetty.
  659.   There exist programs that read terminal settings from files /etc/ttys
  660.   and /etc/ttytype. If you have such files, and create additional
  661.   consoles, then it might be a good idea to also add entries for them in
  662.   these files.
  663.  
  664.   8.  Ctrl-Alt-Del and other special key combinations
  665.  
  666.   8.1.  Ctrl-Alt-Del (Boot)
  667.  
  668.   If you press Ctrl-Alt-Del (or whatever key was assigned the keysym
  669.   Boot by loadkeys) then either the machine reboots immediately (without
  670.   sync), or init is sent a SIGINT. The former behaviour is the default.
  671.   The default can be changed by root, using the system call reboot(),
  672.   see ctrlaltdel(8).  Some init's change the default. What happens when
  673.   init gets SIGINT depends on the version of init used - often it will
  674.   be determined by the pf entry in /etc/inittab (which means that you
  675.   can run an arbitrary program in this case).  In the current kernel
  676.   Ctrl-AltGr-Del is no longer by default assigned to Boot.
  677.  
  678.   8.2.  Other combinations
  679.  
  680.   Name            Default binding
  681.   -------------------------------
  682.   Show_Memory     Shift-Scrollock
  683.   Show_Registers  AltGr-ScrollLock
  684.   Show_State      Ctrl-ScrollLock
  685.   Console_n       Alt-Fn and Ctrl-Alt-Fn  (1 <= n <= 12)
  686.   Console_{n+12}  AltGr-Fn                (1 <= n <= 12)
  687.   Incr_Console    Alt-RightArrow
  688.   Decr_Console    Alt-LeftArrow
  689.   Last_Console    Alt[Gr]-PrintScreen
  690.   Scroll_Backward Shift-PageUp
  691.   Scroll_Forward  Shift-PageDown
  692.   Caps_On                                 (CapsLock is a toggle; this key sets)
  693.   Compose         Ctrl-.
  694.  
  695.   8.3.  X Combinations
  696.  
  697.   Ctrl-Alt-Fn     Switch to VT n
  698.   Ctrl-Alt-KP+    Next mode
  699.   Ctrl-Alt-KP-    Previous mode
  700.   Ctrl-Alt-Backspace      Kill X
  701.  
  702.   On some motherboards, Ctrl-Alt-KP- and Ctrl-Alt-KP+ will be equivalent
  703.   to pressing the Turbo button. That is, both will produce the scancodes
  704.   1d 38 4a ca b8 9d and 1d 38 4e ce b8 9d, and both will switch between
  705.   Turbo (>= 25MHz) and non-Turbo (8 or 12 MHz).  (Often these key combi¡
  706.   nations only function this way when enabled by jumpers on the mother¡
  707.   board.)
  708.  
  709.   Perry F Nguyen (pfnguyen@netcom22.netcom.com) writes: AMI BIOS has a
  710.   feature that locks up the keyboard and flashes the LED's if the Ctrl-
  711.   Alt-Backspace combination is pressed while a BIOS password is enabled,
  712.   until the CMOS/BIOS password is typed in.
  713.  
  714.   8.4.  Dosemu Combinations
  715.  
  716.   Ctrl-Alt-Fn     Switch to VT n (from version 0.50; earlier Alt-Fn)
  717.   Ctrl-Alt-PgDn   Kill dosemu (when in RAW keyboard mode)
  718.   (and many other combinations - see the dosemu documentation)
  719.  
  720.   8.5.  Composing symbols
  721.  
  722.   One symbol may be constructed using several keystrokes.
  723.  
  724.   ╖  LeftAlt-press, followed by a decimal number typed on the keypad,
  725.      followed by LeftAlt-release, yields the symbol with code given by
  726.      this number.  (In Unicode mode this same mechanism, but then with 4
  727.      hexadecimal digits, may be used to define a Unicode symbol.)
  728.  
  729.   ╖  A dead diacritic followed by a symbol, yields that symbol adorned
  730.      with that diacritic. If the combination is undefined, both keys are
  731.      taken separately.  Which keys are dead diacritics is user-settable;
  732.      none is by default.  Five (since 2.0.25 six) dead diacritics can be
  733.      defined (using loadkeys(1)): dead_grave, dead_acute,
  734.      dead_circumflex, dead_tilde, dead_diaeresis (and dead_cedilla).
  735.      Precisely what this adorning means is also user-settable: dead-
  736.      diacritic, symbol is equivalent to Compose + diacritic + symbol.
  737.  
  738.   ╖  Compose followed by two symbols yields a combination symbol. These
  739.      combinations are user-settable. Today there are 68 combinations
  740.      defined by default; you can see them by saying "dumpkeys | grep
  741.      compose".
  742.  
  743.   ╖  Then there are `Sticky' modifier keys (since 1.3.33). For example,
  744.      one can type ^C as SControl, C and Ctrl-Alt-BackSpace as SControl,
  745.      SAlt, BackSpace.
  746.  
  747.   Note that there are at least three such composition mechanisms:
  748.  
  749.   1. The Linux keyboard driver mechanism, used in conjunction with
  750.      loadkeys.
  751.  
  752.   2. The X mechanism - see X386keybd(1), later XFree86kbd(1).  Under
  753.      X11R6: edit /usr/X11R6/lib/X11/locale/iso8859-1/Compose.
  754.  
  755.   3. The emacs mechanism obtained by loading "iso-insert.el" or calling
  756.      `iso-accents-mode'.
  757.  
  758.      For X the order of the two symbols is arbitrary: both Compose-,-c
  759.      and Compose-c-, yield a c-cedilla; for Linux and emacs only the
  760.      former sequence works by default. For X the list of compose
  761.      combinations is fixed. Linux and emacs are flexible.  The three
  762.      default lists are somewhat similar, but the details are different.
  763.  
  764.   9.  How to get out of raw mode
  765.  
  766.   If some program using K_RAW keyboard mode exits without restoring the
  767.   keyboard mode to K_XLATE, then it is difficult to do anything - not
  768.   even Ctrl-Alt-Del works. However, it is sometimes possible to avoid
  769.   hitting the reset button.  (And desirable as well: your users may get
  770.   angry if you kill their Hack game by rebooting; you might also damage
  771.   your file system.)  Easy solutions involve logging in from another
  772.   terminal or another machine and doing kbd_mode -a.  The procedure
  773.   below assumes that no X is running, that the display is in text mode,
  774.   and that you are at your bash prompt, that you are using a US keyboard
  775.   layout, and that your interrupt character is Ctrl-C.
  776.  
  777.   Step 1. Start X.  As follows: press 2 (and don't release), press F12
  778.   (and don't release) and immediately afterwards press = . This starts
  779.   X.  (Explanation: if a key press produces keycode K, then the key
  780.   release produces keycode K+128. Probably your shell does not like
  781.   these high characters, so we avoid generating them by not releasing
  782.   any key.  However, we have to be quick, otherwise key repeat starts.
  783.   The digit 2 produces a Ctrl-C that discards previous junk, the F12
  784.   produces an X and the = a Return.)  Probably your screen will be grey
  785.   now, since no .xinitrc was specified.  However, Ctrl-Alt-Fn will work
  786.   and you can go to another VT.  (Ctrl-Alt-Backspace also works, but
  787.   that exits X, and gets you back into the previous state, which is not
  788.   what you want.)
  789.  
  790.   Step 2. Setup to change the keyboard mode.  (For example, by sleep 5;
  791.   kbd_mode -a.)
  792.  
  793.   Step 3. Leave X again.  Alt-Fx (often Alt-F7) brings you back to X,
  794.   and then Ctrl-Alt-Backspace exits X. Within 5 seconds your keyboard
  795.   will be usable again.
  796.  
  797.   If you want to prepare for the occasion, then make \215A\301 (3
  798.   symbols) an alias for kbd_mode -a.  Now just hitting = F7 = (3
  799.   symbols) will return you to sanity.
  800.  
  801.   10.  The keyboard LEDs
  802.  
  803.   1. There are per-tty keyboard flags: each VC has its own NumLock,
  804.   CapsLock, ScrollLock.  By default these keyboard flags are shown in
  805.   the LEDs.  The usual way to change them is by pressing the
  806.   corresponding key.  (Side remark: pressing the NumLock key when in
  807.   application key mode will not change the NumLock status, but produce
  808.   an escape sequence.  If you want the NumLock key to always change the
  809.   Numlock status, bind it to Bare_Num_Lock.)
  810.  
  811.   2. Next, there are per-tty default keyboard flags, to initialize the
  812.   keyboard flags when a reset occurs.  Thus if you want NumLock on all
  813.   the time, that is possible.  The usual way to change them is by
  814.   `setleds -D ...'.
  815.  
  816.   3. There is the possibility that the leds do not reflect the keyboard
  817.   flags, but something else.
  818.  
  819.   3A. This something else can be three bits somewhere in the kernel -
  820.   which can be used if you want to monitor some hardware or software
  821.   status bit(s). If you want this, edit the kernel source to call
  822.   register_leds() somewhere.
  823.  
  824.   3B. This something else can also be whatever some user program wants
  825.   to show in the LEDs. Thus, people who like such things can make nice
  826.   patterns of lights. If you want this, use the KDSETLED ioctl.
  827.  
  828.   This latter use is not per-tty, but the choice between former and
  829.   latter use is per-tty.
  830.  
  831.   Summarizing: Each tty has a flag kbd->ledmode.  If this has the value
  832.   LED_SHOW_FLAGS then the keyboard flags (NumLock etc.) of that tty are
  833.   shown.  If this has the value LED_SHOW_MEM then three selected memory
  834.   addresses are shown.  If this has the value LED_SHOW_IOCTL then the
  835.   leds show whatever value was last assigned to them using the KDSETLED
  836.   ioctl.
  837.   One may add that X uses ioctl's to set the LEDs, but fails to reset
  838.   its VT when it exits, so after using X there may be one VT that is not
  839.   in the default LED_SHOW_FLAGS state.  This can be fixed by doing
  840.   `setleds -L' on that VT.  See setleds(1).
  841.  
  842.   11.  The TERM variable
  843.  
  844.   Many programs use the TERM variable and the database /etc/termcap or
  845.   /usr/lib/terminfo/* to decide which strings to send for clear screen,
  846.   move cursor, etc., and sometimes also to decide which string is sent
  847.   by the users backspace key, function keys etc.  This value is first
  848.   set by the kernel (for the console).  Usually, this variable is re-set
  849.   by getty, using /etc/ttytype or the argument specified in
  850.   /etc/inittab.  Sometimes, it is also set in /etc/profile.
  851.  
  852.   Older systems use TERM=console or TERM=con80x25. Newer systems (with
  853.   ncurses 1.8.6) use the more specific TERM=linux or TERM=linux-80x25.
  854.   However, old versions of setterm test for TERM=con* and hence fail to
  855.   work with TERM=linux.
  856.  
  857.   Since kernel version 1.3.2, the kernel default for the console is
  858.   TERM=linux.
  859.  
  860.   If you have a termcap without entry for linux, add the word linux to
  861.   the entry for the console:
  862.  
  863.                console|con80x25|linux:\
  864.  
  865.   and make /usr/lib/terminfo/l/linux a copy of or symbolic link to
  866.   /usr/lib/terminfo/c/console.
  867.  
  868.   11.1.  Terminfo
  869.  
  870.   The terminfo entry for the linux console from ncurses 1.8.6 misses the
  871.   entry kich1=\E[2~, needed by some programs.  Edit the file and tic it.
  872.  
  873.   12.  How to make other programs work with non-ASCII chars
  874.  
  875.   In the bad old days this used to be quite a hassle. Every separate
  876.   program had to be convinced individually to leave your bits alone.
  877.   Not that all is easy now, but recently a lot of gnu utilities have
  878.   learned to react to LC_CTYPE=iso_8859_1 or LC_CTYPE=iso-8859-1.  Try
  879.   this first, and if it doesn't help look at the hints below.  Note that
  880.   in recent versions of libc the routine setlocale() only works if you
  881.   have installed the locale files (e.g. in /usr/lib/locale).
  882.  
  883.   First of all, the 8-th bit should survive the kernel input processing,
  884.   so make sure to have stty cs8 -istrip -parenb set.
  885.  
  886.   A. For emacs the details strongly depend on the version.  The
  887.   information below is for version 19.34. Put lines
  888.  
  889.           (set-input-mode nil nil 1)
  890.           (standard-display-european t)
  891.           (require 'iso-syntax)
  892.  
  893.   into your $HOME/.emacs.  The first line (to be precise: the final 1)
  894.   tells emacs not to discard the 8-th bit from input characters.  The
  895.   second line tells emacs not to display non-ASCII characters as octal
  896.   escapes.  The third line specifies the syntactic properties and case
  897.   conversion table for the Latin-1 character set These last two lines
  898.   are superfluous if you have something like LC_CTYPE=ISO-8859-1 in your
  899.   environment.  (The variable may also be LC_ALL or even LANG.  The
  900.   value may be anything with a substring `88591' or `8859-1' or
  901.   `8859_1'.)
  902.  
  903.   This is a good start.  On a terminal that cannot display non-ASCII ISO
  904.   8859-1 symbols, the command
  905.  
  906.                (load-library "iso-ascii")
  907.  
  908.   will cause accented characters to be displayed comme {,c}a.  If your
  909.   keymap does not make it easy to produce non-ASCII characters, then
  910.  
  911.                (load-library "iso-transl")
  912.  
  913.   will make the 2-character sequence Ctrl-X 8 a compose character, so
  914.   that the 4-character sequence Ctrl-X 8 , c produces c-cedilla.  Very
  915.   inconvenient.
  916.  
  917.   The command
  918.  
  919.                (iso-accents-mode)
  920.  
  921.   will toggle ISO-8859-1 accent mode, in which the six characters ', `,
  922.   ", ^, ~, / are dead keys modifying the following symbol.  Special com¡
  923.   binations: ~c gives a c with cedilla, ~d gives an Icelandic eth, ~t
  924.   gives an Icelandic thorn, "s gives German sharp s, /a gives a with
  925.   ring, /e gives an a-e ligature, ~< and ~> give guillemots, ~! gives an
  926.   inverted exclamation mark, ~? gives an inverted question mark, and ''
  927.   gives an acute accent.  This is the default mapping of accents.  The
  928.   variable iso-languages is a list of pairs (language name, accent map¡
  929.   ping), and a non-default mapping can be selected using
  930.  
  931.                (iso-accents-customize LANGUAGE)
  932.  
  933.   Here LANGUAGE can be one of "portuguese", "irish", "french",
  934.   "latin-2", "latin-1".
  935.  
  936.   Since the Linux default compose character is Ctrl-.  it might be
  937.   convenient to use that everywhere. Try
  938.  
  939.                (load-library "iso-insert.el")
  940.                (define-key global-map [?\C-.] 8859-1-map)
  941.  
  942.   The latter line will not work under xterm, if you use emacs -nw, but
  943.   in that case you can put
  944.  
  945.                XTerm*VT100.Translations:       #override\n\
  946.                      Ctrl <KeyPress> . : string("\0308")
  947.  
  948.   in your .Xresources.)
  949.  
  950.   B. For less, put LESSCHARSET=latin1 in the environment.  This is also
  951.   what you need if you see \255 or <AD> in man output: some versions of
  952.   less will render the soft hyphen (octal 0255, hex 0xAD) this way when
  953.   not given permission to output Latin-1.
  954.  
  955.   C. For ls, give the option -N. (Probably you want to make an alias.)
  956.  
  957.   D. For bash (version 1.13.*), put
  958.  
  959.                set meta-flag on
  960.                set convert-meta off
  961.  
  962.   and, according to the Danish HOWTO,
  963.  
  964.                set output-meta on
  965.  
  966.   into your $HOME/.inputrc.
  967.  
  968.   E. For tcsh, use
  969.  
  970.                setenv LANG     US_en
  971.                setenv LC_CTYPE iso_8859_1
  972.  
  973.   If you have nls on your system, then the corresponding routines are
  974.   used.  Otherwise tcsh will assume iso_8859_1, regardless of the values
  975.   given to LANG and LC_CTYPE. See the section NATIVE LANGUAGE SYSTEM in
  976.   tcsh(1).  (The Danish HOWTO says: setenv LC_CTYPE ISO-8859-1; stty
  977.   pass8)
  978.  
  979.   F. For flex, give the option -8 if the parser it generates must be
  980.   able to handle 8-bit input. (Of course it must.)
  981.  
  982.   G. For elm, set displaycharset to ISO-8859-1.  (Danish HOWTO: LANG=C
  983.   and LC_CTYPE=ISO-8859-1)
  984.  
  985.   H. For programs using curses (such as lynx) David Sibley reports: The
  986.   regular curses package uses the high-order bit for reverse video mode
  987.   (see flag _STANDOUT defined in /usr/include/curses.h).  However,
  988.   ncurses seems to be 8-bit clean and does display iso-latin-8859-1
  989.   correctly.
  990.  
  991.   I. For programs using groff (such as man), make sure to use -Tlatin1
  992.   instead of -Tascii. Old versions of the program man also use col, and
  993.   the next point also applies.
  994.  
  995.   J. For col, make sure 1) that it is fixed so as to do
  996.   setlocale(LC_CTYPE,""); and 2) put LC_CTYPE=ISO-8859-1 in the
  997.   environment.
  998.  
  999.   K. For rlogin, use option -8.
  1000.  
  1001.   L. For joe,
  1002.   sunsite.unc.edu:/pub/Linux/apps/editors/joe-1.0.8-linux.tar.gz is said
  1003.   to work after editing the configuration file. Someone else said: joe:
  1004.   Put the -asis option in /isr/lib/joerc in the first column.
  1005.  
  1006.   M. For LaTeX: \documentstyle[isolatin]{article}.  For LaTeX2e:
  1007.   \documentclass{article}\usepackage{isolatin} where isolatin.sty is
  1008.   available from ftp://ftp.vlsivie.tuwien.ac.at/pub/8bit.
  1009.  
  1010.   A nice discussion on the topic of ISO-8859-1 and how to manage 8-bit
  1011.   characters is contained in the file grasp.insa-
  1012.   lyon.fr:/pub/faq/fr/accents (in French). Another fine discussion (in
  1013.   English) can be found in ftp.vlsivie.tuwien.ac.at:/pub/8bit/FAQ-
  1014.   ISO-8859-1, which is mirrored in rtfm.mit.edu:pub/usenet-by-
  1015.   group/comp.answers/character-sets/iso-8859-1-faq.
  1016.  
  1017.   If you need to fix a program that behaves badly with 8-bit characters,
  1018.   one thing to keep in mind is that if you have a signed char type then
  1019.   characters may be negative, and using them as an array index will
  1020.   fail.  Several programs can be fixed by judiciously adding (unsigned
  1021.   char) casts.
  1022.  
  1023.   13.  What precisely does XFree86-2.1 do when it initializes its
  1024.   keymap?
  1025.  
  1026.   Since version 2.1, XFree86 will initialize its keymap from the Linux
  1027.   keymap, as far as possible. However, Linux had 16 entries per key (one
  1028.   for each combination of the Shift, AltGr, Ctrl, Alt modifiers) and
  1029.   presently has 256 entries per key, while X has 4 entries per key (one
  1030.   for each combination of Shift, Mod), so some information is
  1031.   necessarily lost.
  1032.  
  1033.   First X reads the Xconfig file, where definitions of the LeftAlt,
  1034.   RightAlt, RightCtl, ScrollLock keys as Meta, ModeShift, Compose,
  1035.   ModeLock or ScrollLock might be found - see X386keybd(1), later
  1036.   XFree86kbd(1).
  1037.  
  1038.   For Mod the LeftAlt key is taken, unless RightCtl was defined as
  1039.   ModeShift or ModeLock, in which case RightCtl is taken, or RightAlt
  1040.   was so defined, in which case RightAlt is taken.  This determines how
  1041.   the 4 XFree86 meanings of a key are selected from the 16 Linux
  1042.   meanings.  Note that Linux today does not distinguish by default
  1043.   between the two Ctrl keys or between the two Shift keys. X does
  1044.   distinguish.
  1045.  
  1046.   Now the kernel keymap is read and the usually obvious corresponding X
  1047.   bindings are made. The bindings for the "action keys" Show_Memory,
  1048.   Show_State, Show_Registers, Last_Console, Console_n, Scroll_Backward,
  1049.   Scroll_Forward, Caps_On and Boot are ignored, as are the dead
  1050.   diacriticals, and the locks (except for ShiftLock), and the "ASCII-x"
  1051.   keys.
  1052.  
  1053.   Next, the definitions in the Xconfig file are used. (Thus, a
  1054.   definition of Compose in Xconfig will override its value as found in
  1055.   the Linux keymap.)
  1056.  
  1057.   What happens to the strings associated with the function keys?
  1058.   Nothing, X does not have such a concept. (But it is possible to define
  1059.   strings for function keys in xterm - note however that the window
  1060.   manager gets the keys first.)
  1061.  
  1062.   I don't know how to convince xterm that it should use the X keymap
  1063.   when Alt is pressed; it seems just to look at its resource
  1064.   eightBitInput, and depending on whether that is true or false either
  1065.   set the high order bit of the character, or generate an additional
  1066.   Escape character (just like setmetamode(1) does for the console).
  1067.  
  1068.   14.  Unusual keys and keyboards
  1069.  
  1070.   The two keys PrintScrn/SysRq and Pause/Break are special in that they
  1071.   have two keycodes: the former has keycode 84 when Alt is pressed
  1072.   simultaneously, and keycode 99 otherwise; the latter has keycode 101
  1073.   when Ctrl is pressed simultaneously, and keycode 119 otherwise.
  1074.   (Thus, it makes no sense to bind functions to Alt keycode 99 or Ctrl
  1075.   keycode 119.)
  1076.  
  1077.   If you have strange keys, that do not generate any code under Linux
  1078.   (or generate messages like "unrecognized scancode"), and your kernel
  1079.   is 1.1.63 or later, then you can use setkeycodes(1) to tell the kernel
  1080.   about them. They won't work under X, however.  Once they have gotten a
  1081.   keycode from setkeycodes, they can be assigned a function by loadkeys.
  1082.  
  1083.   15.  Examples of use of loadkeys and xmodmap
  1084.  
  1085.   Switching Caps Lock and Control on the keyboard (assuming you use
  1086.   keymaps 0-15; check with dumpkeys | head -1)
  1087.  
  1088.                % loadkeys
  1089.                keymaps 0-15
  1090.                keycode 58 = Control
  1091.                keycode 29 = Caps_Lock
  1092.                %
  1093.  
  1094.   Switching them under X only:
  1095.  
  1096.                % xmodmap .xmodmaprc
  1097.  
  1098.   where .xmodmaprc contains lines
  1099.  
  1100.           remove Lock = Caps_Lock
  1101.           remove Control = Control_L
  1102.           keysym Control_L = Caps_Lock
  1103.           keysym Caps_Lock = Control_L
  1104.           add Lock = Caps_Lock
  1105.           add Control = Control_L
  1106.  
  1107.   What is this about the key numbering? Backspace is 14 under Linux, 22
  1108.   under X?  Well, the numbering can best be regarded as arbitrary; the
  1109.   Linux number of a key can be found using showkey(1), and the X number
  1110.   using xev(1). Often the X number will be 8 more than the Linux number.
  1111.  
  1112.   Something else people like to change are the bindings of the function
  1113.   keys.  Suppose that you want to make F12 produce the string "emacs ".
  1114.   Then
  1115.  
  1116.                % loadkeys
  1117.                keycode 88 = F12
  1118.                string F12 = "emacs "
  1119.                %
  1120.  
  1121.   will do this. More explicitly, the procedure is like this: (i) find
  1122.   the keycodes of the keys to be remapped, using showkey(1).  (ii) save
  1123.   the current keymap, make a copy and edit that:
  1124.  
  1125.                % dumpkeys > my_keymap
  1126.                % cp my_keymap trial_keymap
  1127.                % emacs trial_keymap
  1128.                % loadkeys trial_keymap
  1129.                %
  1130.  
  1131.   The format of the table can be guessed by looking at the output of
  1132.   dumpkeys, and is documented in keytables(5).  When the new keymap
  1133.   functions as desired, you can put an invocation
  1134.  
  1135.                loadkeys my_new_keymap
  1136.  
  1137.   in /etc/rc.local or so, to execute it automatically at boot-up.  Note
  1138.   that changing modifier keys is tricky, and a newbie can easily get
  1139.   into a situation only an expert can get out of.
  1140.  
  1141.   The default directory for keymaps is /usr/lib/kbd/keytables.  The
  1142.   default extension for keymaps is .map.  Thus, loadkeys uk would
  1143.   probably load /usr/lib/kbd/keytables/uk.map.
  1144.  
  1145.   (On my machine) /dev/console is a symbolic link to /dev/tty0, and the
  1146.   kernel regards /dev/tty0 as a synonym for the current VT.  XFree86 1.3
  1147.   changes the owner of /dev/tty0, but does not reset this after
  1148.   finishing. Thus, loadkeys or dumpkeys might fail because someone else
  1149.   owns /dev/tty0; in such a case you might run X first.  Note that you
  1150.   cannot change keyboard mappings when not at the console (and not
  1151.   superuser).
  1152.  
  1153.   15.1.  `I can use only one finger to type with'
  1154.  
  1155.   "Can the Shift, Ctrl and Alt keys be made to behave as toggles?"
  1156.  
  1157.   Yes, after saying
  1158.  
  1159.                % loadkeys
  1160.                keycode 29 = Control_Lock
  1161.                keycode 42 = Shift_Lock
  1162.                keycode 56 = Alt_Lock
  1163.                %
  1164.  
  1165.   the left Control, Shift and Alt keys will act as toggles.  The numbers
  1166.   involved are revealed by showkey (and usually are 29, 97, 42, 54, 56,
  1167.   100 for left and right control, shift and alt, respectively), and the
  1168.   functions are Control_Lock, Shift_Lock, Alt_Lock, ALtGr_Lock.
  1169.  
  1170.   "What about `sticky' modifier keys?"
  1171.  
  1172.   Since version 1.3.33, the kernel knows about `sticky' modifier keys.
  1173.   These act on the next key pressed. So, where one earlier needed the
  1174.   3-symbol sequence Shift_Lock a Shift_Lock to type `A', one can now use
  1175.   the 2-symbol sequence SShift_Lock a.  Versions of the kbd package
  1176.   older than 0.93 do not yet include code for these sticky modifiers,
  1177.   and have to invoke them using their hexadecimal codes. For example,
  1178.  
  1179.                % loadkeys
  1180.                keymaps 0-15
  1181.                keycode 54 = 0x0c00
  1182.                keycode 97 = 0x0c02
  1183.                keycode 100 = 0x0c03
  1184.                %
  1185.  
  1186.   will make the right Shift, Ctrl, Alt sticky versions of the left ones.
  1187.   >From 0.93 on you can say
  1188.  
  1189.                % loadkeys
  1190.                keymaps 0-15
  1191.                keycode 54 = SShift
  1192.                keycode 97 = SCtrl
  1193.                keycode 100 = SAlt
  1194.                %
  1195.  
  1196.   to obtain the same result.  This will allow you to type Ctrl-Alt-Del
  1197.   in three keystrokes with one hand.
  1198.  
  1199.   16.  Changing the video mode
  1200.  
  1201.   As far as I know there are 6 ways to change resolution:
  1202.  
  1203.   1. At compile time: change the line
  1204.  
  1205.                SVGA_MODE=      -DSVGA_MODE=NORMAL_VGA
  1206.  
  1207.   in /usr/src/linux/Makefile.
  1208.  
  1209.   1A. After compilation: use rdev -v - a terrible hack, but it exists.
  1210.  
  1211.   2. At boot time: put vga=ask in the lilo config file, and lilo will
  1212.   ask you what video mode you want. Once you know, put vga=mypreference.
  1213.  
  1214.   3. At run time: A. Use the resizecons command. (This is a very
  1215.   primitive wrapper around the VT_RESIZE ioctl.)  B. Use the
  1216.   SVGATextMode command. (This is a less primitive wrapper around the
  1217.   VT_RESIZE ioctl.)
  1218.  
  1219.   4. Not "on the console": Under dosemu, or with svgalib etc. you can
  1220.   change the hardware video mode without the console driver being aware
  1221.   of it. Sometimes this is useful in getting resizecons or SVGATextMode
  1222.   set up: use dosemu and some DOS program to get into the desired
  1223.   videomode, dump (say from another VT) the contents of all video
  1224.   hardware registers, and use that in the initialization that resizecons
  1225.   and SVGATextMode require.  In some cases where the video mode has
  1226.   gotten into some unusable state, starting dosemu, relying on the BIOS
  1227.   to set up the video mode, and then killing dosemu (with kill -9), is
  1228.   the easiest way to get into shape again.
  1229.  
  1230.   16.1.  Instructions for the use of resizecons
  1231.  
  1232.   Get svgalib and compile the program restoretextmode.  Boot up your
  1233.   machine in all possible video modes (using vga=ask in the lilo config
  1234.   file), and write the video hardware register contents to files CxR
  1235.   (C=cols, R=rows), e.g., 80x25, 132x44, etc.  Put these files in
  1236.   /usr/lib/kbd/videomodes.  Now resizecons 132x44 will change videomode
  1237.   for you (and send SIGWINCH to all processes that need to know about
  1238.   this, and load another font if necessary).
  1239.  
  1240.   At present, resizecons only succeeds when there is memory enough for
  1241.   both the old and the new consoles at the same time.
  1242.  
  1243.   17.  Changing the keyboard repeat rate
  1244.  
  1245.   At startup, the Linux kernel sets the repeat rate to its maximal
  1246.   value.  For most keyboards this is reasonable, but for some it means
  1247.   that you can hardly touch a key without getting three copies of the
  1248.   corresponding symbol. Use the program kbdrate(8) to change the repeat
  1249.   rate, or, if that doesn't help, edit or remove the section
  1250.  
  1251.   ______________________________________________________________________
  1252.        ! set the keyboard repeat rate to the max
  1253.  
  1254.            mov     ax,#0x0305
  1255.            xor     bx,bx           ! clear bx
  1256.            int     0x16
  1257.   ______________________________________________________________________
  1258.  
  1259.   of /usr/src/linux/[arch/i386/]boot/setup.S.
  1260.  
  1261.   18.  Scrolling
  1262.  
  1263.   There are two ways to get a screen to scroll.  The first, called `hard
  1264.   scrolling', is to leave the text in video memory as it is, but change
  1265.   the viewing origin. This is very fast.  The second, called `soft
  1266.   scrolling', involves moving all screen text up or down. This is much
  1267.   slower.  The kernel console driver will write text starting at the top
  1268.   of the video memory, continuing to the bottom, then copy the bottom
  1269.   part to the top again, and continue, all the time using hard scrolling
  1270.   to show the right part on the screen.  You can scroll back until the
  1271.   top op the video memory by using Shift-PageUp (the grey PageUp) and
  1272.   scroll down again using Shift-PageDown (the grey PageDown), assuming a
  1273.   default keymap.  The amount of scrollback is thus limited to the
  1274.   amount of video memory you happen to have and you cannot increase this
  1275.   amount.  If you need more scrollback, use some program that buffers
  1276.   the text, like less or screen - by using a buffer on disk you can go
  1277.   back to what you did last week.  (One can set the amount of scrollback
  1278.   for xterm by adding a line like XTerm*saveLines: 2500 in .Xresources.)
  1279.  
  1280.   Upon changing virtual consoles, the screen content of the old VT is
  1281.   copied to kernel memory, and the screen content of the new VT is
  1282.   copied from kernel memory to video memory. Only the visible screen is
  1283.   copied, not all of video memory, so switching consoles means losing
  1284.   the scrollback information.
  1285.  
  1286.   Sometimes, hard scrolling is undesirable, for example when the
  1287.   hardware does not have the possibility to change viewing origin. The
  1288.   first example was a Braille machine that would render the top of video
  1289.   memory in Braille. There is a kernel boot-time option no-scroll to
  1290.   tell the console driver not to use hard scrolling.  See bootparam(7).
  1291.  
  1292.   19.  Screensaving
  1293.  
  1294.   setterm -blank nn will tell the console driver to blank the screen
  1295.   after nn minutes of inactivity. (With nn = 0, screensaving is turned
  1296.   off. In some old kernels this first took effect after the next
  1297.   keyboard interrupt.)
  1298.  
  1299.   The s option of xset(1) will set the X screensaving parameters: xset s
  1300.   off turns off the screensaver, xset s 10 blanks the screen after 10
  1301.   minutes.
  1302.  
  1303.   The video hardware powersaving modes can be enabled/disabled using the
  1304.   setvesablank program given in the starting comment of
  1305.   /usr/src/linux/drivers/char/vesa_blank.c.
  1306.  
  1307.   20.  Screen dumps
  1308.  
  1309.   setterm -dump N will dump the contents of the screen of /dev/ttyN to a
  1310.   file screen.dump in the current directory. See setterm(1).
  1311.  
  1312.   The current contents of the screen of /dev/ttyN can be accessed using
  1313.   the device /dev/vcsN (where `vcs' stands for `virtual console
  1314.   screen').  For example, you could have a clock program that displays
  1315.   the current time in the upper right hand corner of the console screen
  1316.   (see the program vcstime in kbd-0.94.tar.gz).  Just dumping the
  1317.   contents goes with cat /dev/vcsN.  These device files /dev/vcsN do not
  1318.   contain newlines, and do not contain attributes, like colors. From a
  1319.   program it is usually better to use /dev/vcsaN (`virtual console
  1320.   screen with attributes') instead - it starts with a header giving the
  1321.   number of rows and columns and the location of the cursor.  See
  1322.   vcs(4).
  1323.  
  1324.   21.  Some properties of the VT100 - application key mode
  1325.  
  1326.   : Sometimes my cursor keys or keypad keys produce strange codes?
  1327.  
  1328.   When the terminal is in application cursor key mode the cursor keys
  1329.   produce  Esc O x  and otherwise  Esc [ x  where x is one of A,B,C,D.
  1330.   Certain programs put the terminal in application cursor key mode; if
  1331.   you kill them with kill -9, or if they crash, then the mode will not
  1332.   be reset.
  1333.  
  1334.           % echo -e '\033c'
  1335.  
  1336.   resets all properties of the current VC. Just changing the cursor
  1337.   application key mode is done by
  1338.  
  1339.           % echo -e '\033[?1h'
  1340.  
  1341.   (set) and
  1342.  
  1343.           % echo -e '\033[?1l'
  1344.  
  1345.   (clear).
  1346.  
  1347.   When the terminal is in application keypad key mode the keypad keys
  1348.   produce  Esc O y  and otherwise  Esc [ z ~  for certain y and z.
  1349.   Setting application keypad key mode is done by
  1350.  
  1351.           % echo -e '\033='
  1352.  
  1353.   and
  1354.  
  1355.           % echo -e '\033>'
  1356.  
  1357.   clears it again.
  1358.  
  1359.   22.  Hardware incompatibility
  1360.  
  1361.   Several people have noticed that they lose typed characters when a
  1362.   floppy disk is active. It seems that this might be a problem with
  1363.   Uni-486WB motherboards.  (Please mail me (aeb@cwi.nl) to confirm [yes,
  1364.   I have the same problem], deny [no, nothing wrong with my Uni-486WB],
  1365.   modify [My Xyzzy machine has the same problem].)
  1366.   Tjalling Tjalkens (tjalling@ei.ele.tue.nl) reports very similar
  1367.   problems with "a no-brand GMB-486 UNP Vesa motherboard with AMD
  1368.   486DX2-66 CPU" - during floppy activity some keystrokes are lost,
  1369.   during floppy tape streamer (Conner C 250 MQ) activity many keystrokes
  1370.   are lost.
  1371.  
  1372.   Some people experience sporadic lockups - sometimes associated to hard
  1373.   disk activity or other I/O.
  1374.  
  1375.   Ulf Tietz (ulf@rio70.bln.sni.de) wrote: `I have had the same problems,
  1376.   when I had my motherboard tuned too fast.  So I reset all the timings
  1377.   ( CLK, wait statements etc ) to more conventional values, and the
  1378.   problems are gone.'
  1379.  
  1380.   Bill Hogan (bhogan@crl.com) wrote: `If you have an AMI BIOS, you might
  1381.   try setting the Gate A20 emulation parameter to "chipset" (if you have
  1382.   that option). Whenever I have had that parameter set to any of the
  1383.   other options on my machine ("fast", "both", "disabled") I have had
  1384.   frequent keyboard lockups.'
  1385.  
  1386.   --------------------------------------------------------------------
  1387.  
  1388.   Additions and corrections are welcome.  Andries Brouwer - aeb@cwi.nl
  1389.  
  1390.