home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 13 / CDA13.ISO / DOC / HOWTO / KEYBOARD.GZ / KEYBOARD
Encoding:
Text File  |  1996-03-14  |  36.1 KB  |  900 lines

  1.   The Linux Keyboard HOWTO
  2.   Andries Brouwer, aeb@cwi.nl
  3.   v2.1, 8 November 1995
  4.  
  5.   This note contains some information about the Linux keyboard and con¡
  6.   sole, and the use of non-ASCII characters.
  7.  
  8.   1.  Useful programs
  9.  
  10.   The following packages contain keyboard or console related programs.
  11.  
  12.   kbd-0.90.tar.gz contains loadkeys, dumpkeys, showkey, setmetamode,
  13.   setleds, setfont, showfont, mapscrn, kbd_mode, chvt, resizecons,
  14.   disalloc, getkeycodes, setkeycodes.
  15.  
  16.   util-linux-2.5 contains setterm, kbdrate.
  17.  
  18.   shellutils-1.8 (or stty.tar.gz) contains stty.
  19.  
  20.   open-1.1.tgz contains open. (See also dynamic-vc-1.1.tar.gz.)
  21.  
  22.   SVGATextMode-0.9.tar.gz contains SVGATextMode.
  23.  
  24.   The X distribution contains xmodmap, xset, kbd_mode.  (See also
  25.   X386keybd(1).)
  26.  
  27.   2.  Keyboard generalities
  28.  
  29.   You press a key, and the keyboard controller sends scancodes to the
  30.   kernel keyboard driver. Some keyboards can be programmed, but usually
  31.   the scancodes corresponding to your keys are fixed.  The kernel
  32.   keyboard driver just transmits whatever it receives to the application
  33.   program when it is in scancode mode, like when X is running.
  34.   Otherwise, it parses the stream of scancodes into keycodes,
  35.   corresponding to key press or key release events.  (A single key press
  36.   can generate up to 6 scancodes.)  These keycodes are transmitted to
  37.   the application program when it is in keycode mode (as used, for
  38.   example, by showkey).  Otherwise, these keycodes are looked up in the
  39.   keymap, and the character or string found there is transmitted to the
  40.   application, or the action described there is performed.  (For
  41.   example, if one presses and releases the a key, then the keyboard
  42.   produces scancodes 0x1e and 0x9e, this is converted to keycodes 30 and
  43.   158, and then transmitted as 0141, the ASCII or latin-1 code for 'a';
  44.   if one presses and releases Delete, then the keyboard produces
  45.   scancodes 0xe0 0x53 0xe0 0xd3, these are converted to keycodes 111 and
  46.   239, and then transmitted as the 4-symbol sequence ESC [ 3 ~, all
  47.   assuming a US keyboard and a default keymap. An example of a key
  48.   combination to which an action is assigned is Ctrl-Alt-Del.)
  49.  
  50.   The translation between unusual scancodes and keycodes can be set
  51.   using the utility setkeycodes - only very few people will need it.
  52.   The translation between keycodes and characters or strings or actions,
  53.   that is, the keymap, is set using the utility loadkeys.  For details,
  54.   see getkeycodes(8), setkeycodes(8), dumpkeys(1), loadkeys(1).
  55.  
  56.   Where it says `transmitted to the application' in the above
  57.   description, this really means `transmitted to the terminal driver'.
  58.   That is, further processing is just like that of text that comes in
  59.   over a serial line.  The details of this processing are set by the
  60.   program stty.
  61.  
  62.   3.  Console generalities
  63.  
  64.   Conversely, when you output something to the console, it first
  65.   undergoes the standard tty processing, and then is fed to the console
  66.   driver.  The console driver emulates a VT100, and parses the input in
  67.   order to recognize VT100 escape sequences (for cursor movement, clear
  68.   screen, etc.).  The characters that are not part of an escape sequence
  69.   are transformed using a mapping table, and the transformed bytes are
  70.   written in video memory, where they cause the display of character
  71.   shapes found in the video card's character ROM. One can load one's own
  72.   fonts into character ROM using setfont, and load the user mapping
  73.   table using mapscrn.  More details will be given below.
  74.  
  75.   4.  Resetting your terminal
  76.  
  77.   There is garbage on the screen, or all your keystrokes are echoed as
  78.   line drawing characters. What to do?
  79.  
  80.   Many programs will redraw the screen when ^L is typed. This might help
  81.   when there is some modem noise or broadcast message on your screen.
  82.   The command clear will clear the screen.
  83.  
  84.   The command reset will reset the console driver. This helps when the
  85.   screen is full of funny graphic characters, and also if it is reduced
  86.   to the bottom line. If you don't have this command, or if it does
  87.   something else, make your own by putting the following two lines in an
  88.   executable file reset in your PATH:
  89.  
  90.        #!/bin/sh
  91.        echo -e \\033c
  92.  
  93.   that is, you want to send the two characters ESC c to the console.  If
  94.   you loaded some strange font, and want to return to the default,
  95.  
  96.        % setfont
  97.  
  98.   will do (provided you stored the default font in the default place).
  99.   On old terminals output involving tabs may require a delay, and you
  100.   have to say
  101.  
  102.        % stty tab3
  103.  
  104.   (see stty(1)). You can change the video mode using resizecons or SVGA¡
  105.   TextMode.  This usually settles the output side.  On the input side
  106.   there are many things that might be wrong. If X or DOOM or some other
  107.   program using raw mode crashed, your keyboard may still be in raw (or
  108.   mediumraw) mode, and it is difficult to give commands.  (See "How to
  109.   get out of raw mode" below.)
  110.  
  111.   4.1.  Keyboard hardware reset
  112.  
  113.   Things may be wrong on a lower level than Linux knows about.  There
  114.   are at least two distinct lower levels (keyboard and keyboard
  115.   controller) where one can give the command "keyboard disable" to the
  116.   keyboard hardware.  Keyboards can often be programmed to use one out
  117.   of three different sets of scancodes.
  118.  
  119.   However, I do not know of cases where this turned out to be a problem.
  120.  
  121.   Some keyboards have a remapping capability built in.  Stormy Henderson
  122.   (stormy@Ghost.Net) writes: `If it's your keyboard accidently being
  123.   reprogrammed, you can (on a Gateway AnyKey keyboard) press control-
  124.   alt-suspend_macro to reset the keys to normal.'
  125.  
  126.   5.  Delete and Backspace
  127.  
  128.   5.1.  How to tell Unix what character you want to use to delete the
  129.   last typed character
  130.  
  131.        % stty erase ^?
  132.  
  133.   If the character is erased, but in a funny way, then something is
  134.   wrong with your tty settings. If echoprt is set, then erased charac¡
  135.   ters are enclosed between \fR and /.  If echoe is not set, then the
  136.   erase char is echoed (which is reasonable when it is a printing char¡
  137.   acter, like #).  Most people will want stty echoe -echoprt. Saying
  138.   stty sane will do this and more. Saying stty -a shows your current
  139.   settings.  How come this is not right by default? It is, if you use
  140.   the right getty.
  141.  
  142.   Note that many programs (like bash, emacs etc.) have their own
  143.   keybindings (defined in ~/.inputrc, ~/.emacs etc.)  and are unaffected
  144.   by the setting of the erase character.
  145.  
  146.   5.1.1.  `Getty used to do the right thing with DEL and BS but is bro¡
  147.   ken now?'
  148.  
  149.   Earlier, the console driver would do BS Space BS ( 10 40 10) when it
  150.   got a DEL (177).  Nowadays, DEL's are ignored (as they should be,
  151.   since the driver emulates a vt100). Get a better getty, i.e., one that
  152.   does not output DEL.
  153.  
  154.   5.1.2.  `Login behaves differently at the first and second login
  155.   attempts?'
  156.  
  157.   At the first attempt, you are talking to getty. At the second attempt,
  158.   you are talking to login, a different program.
  159.  
  160.   5.2.  How to tell Linux what code to generate when a key is pressed
  161.  
  162.   On the console, or, more precisely, when not in (MEDIUM)RAW mode, use
  163.  
  164.        % loadkeys mykeys.map
  165.  
  166.   and under X use
  167.  
  168.        % xmodmap mykeys.xmap
  169.  
  170.   Note that (since XFree86-2.1) X reads the Linux settings of the
  171.   keymaps when initialising the X keymap. Although the two systems are
  172.   not 100% compatible, this should mean that in many cases the use of
  173.   xmodmap has become superfluous.
  174.  
  175.   If, for example, you want your Backspace key to generate BackSpace
  176.   (^H), instead of the default Delete, then
  177.  
  178.        % loadkeys
  179.        keycode 14 = BackSpace
  180.        %
  181.  
  182.   will do.
  183.  
  184.   5.2.1.  `Why doesn't the Backspace key generate BackSpace by default?'
  185.  
  186.   (i) Because the VT100 had a Delete key above the Enter key.
  187.  
  188.   (ii) Because Linus decided so.
  189.  
  190.   5.3.  How to tell X to interchange Delete and Backspace
  191.  
  192.        % xmodmap -e "keysym BackSpace = Delete" -e "keysym Delete = BackSpace"
  193.  
  194.   Or, if you just want the Backspace key to generate a BackSpace:
  195.  
  196.        % xmodmap -e "keycode 22 = BackSpace"
  197.  
  198.   Or, if you just want the Delete key to generate a Delete:
  199.  
  200.   % xmodmap -e "keycode 107 = Delete"
  201.  
  202.   (but usually this is the default binding already).
  203.  
  204.   5.4.  How to tell emacs what to do when it receives a Delete or
  205.   Backspace
  206.  
  207.   Put in your .emacs file lines like
  208.  
  209.          (global-set-key "\?" 'delete-backward-char)
  210.          (global-set-key "\C-h" 'help-command)
  211.  
  212.   Of course you can bind other commands to other keys in the same way.
  213.  
  214.   5.5.  How to tell emacs to interchange Delete and Backspace
  215.  
  216.   Put in your .emacs file lines
  217.  
  218.          (setq keyboard-translate-table (make-string 128 0))
  219.          (let ((i 0))
  220.          (while (< i 128)
  221.              (aset keyboard-translate-table i i)
  222.              (setq i (1+ i))))
  223.          (aset keyboard-translate-table ?\b ?\^?)
  224.          (aset keyboard-translate-table ?\^? ?\b)
  225.  
  226.   5.6.  How to tell kermit to interchange Delete and Backspace
  227.  
  228.   Put in your .kermrc file the lines
  229.  
  230.          set key \127 \8
  231.          set key \8 \127
  232.  
  233.   5.7.  How to tell xterm about your favourite tty modes
  234.  
  235.   Normally xterm will inherit the tty modes from its invoker.  Under
  236.   xdm, the default erase and kill characters are # and @, as in good old
  237.   Unix Version 6.  If you don't like that, you might put something like
  238.  
  239.          XTerm*ttymodes: erase ^? kill ^U intr ^C quit ^\ eof ^D susp ^Z start ^Q stop ^S eol ^@
  240.  
  241.   in /usr/lib/X11/app-defaults/XTerm or in $HOME/.Xresources, assuming
  242.   that you have a line
  243.  
  244.          xrdb $HOME/.Xresources
  245.  
  246.   in your $HOME/.xinitrc.
  247.  
  248.   5.8.  How to tell xmosaic that the Backspace key generates a DEL
  249.  
  250.   Putting
  251.  
  252.          *XmText.translations: #override\n\
  253.                 <Key>osfDelete: delete-previous-character()
  254.          *XmTextField.translations: #override\n\
  255.                  <Key>osfDelete: delete-previous-character()
  256.  
  257.   in your $HOME/.Xresources helps.
  258.  
  259.   The netscape FAQ, however, says:
  260.  
  261.           Why doesn't my Backspace key work in text fields?
  262.           By default, Linux and XFree86 come with the Backspace and Delete keys
  263.           misconfigured. All Motif programs (including, of course, Netscape
  264.           Navigator) will malfunction in the same way.
  265.  
  266.           The Motif spec says that Backspace is supposed to delete the previous
  267.           character and Delete is supposed to delete the following character.
  268.           Linux and XFree86 come configured with both the Backspace and Delete
  269.           keys generating Delete.
  270.  
  271.           You can fix this by using any one of the xmodmap, xkeycaps, or
  272.           loadkeys programs to make the key in question generate the BackSpace
  273.           keysym instead of Delete.
  274.  
  275.           You can also fix it by having a .motifbind file; see the man page
  276.           for VirtualBindings(3).
  277.  
  278.           Note: Don't use the *XmText.translations or *XmTextField.translations
  279.           resources to attempt to fix this problem. If you do, you will blow away
  280.           Netscape Navigator's other text-field key bindings.
  281.  
  282.   5.9.  What about termcap and terminfo?
  283.  
  284.   When people have problems with backspace, they tend to look at their
  285.   termcap (or terminfo) entry for the terminal, and indeed, there does
  286.   exist a kb (or kbs) capability describing the code generated by the
  287.   Backspace key.  However, not many programs use it, so unless you are
  288.   having problems with one particular program only, probably the fault
  289.   is elsewhere.  Of course it is a good idea anyway to correct your
  290.   termcap (terminfo) entry.  See also below under "The TERM variable".
  291.  
  292.   6.  The console character sets
  293.  
  294.   The kernel knows about 4 translations of bytes into console-screen
  295.   symbols.  The four tables are: a) Latin1 -> PC,  b) VT100 graphics ->
  296.   PC, c) PC -> PC, d) user-defined.
  297.  
  298.   There are two character sets, called G0 and G1, and one of them is the
  299.   current character set. (Initially G0.)  Typing ^N causes G1 to become
  300.   current, ^O causes G0 to become current.
  301.  
  302.   These variables G0 and G1 point at a translation table, and can be
  303.   changed by the user. Initially they point at tables a) and b),
  304.   respectively.  The sequences ESC ( B and ESC ( 0 and ESC ( U and ESC (
  305.   K cause G0 to point at translation table a), b), c) and d),
  306.   respectively.  The sequences ESC ) B and ESC ) 0 and ESC ) U and ESC )
  307.   K cause G1 to point at translation table a), b), c) and d),
  308.   respectively.
  309.  
  310.   The sequence ESC c causes a terminal reset, which is what you want if
  311.   the screen is all garbled. The oft-advised echo ^V^O will only make G0
  312.   current, but there is no guarantee that G0 points at table a).  In
  313.   some distributions there is a program reset(1) that just does echo
  314.   ^[c.  If your termcap entry for the console is correct (and has an
  315.   entry :rs=
  316.  
  317.   The user-defined mapping table can be set using mapscrn(8).  The
  318.   result of the mapping is that if a symbol c is printed, the symbol s =
  319.   map[c] is sent to the video memory. The bitmap that corresponds to s
  320.   is found in the character ROM, and can be changed using setfont(8).
  321.  
  322.   7.  Console switching
  323.  
  324.   By default, console switching is done using Alt-Fn or Ctrl-Alt-Fn.
  325.   Under X (or recent versions of dosemu), only Ctrl-Alt-Fn works.
  326.  
  327.   XFree86 1.3 does not know that Alt is down when you switch to the X
  328.   window. Thus, you cannot switch immediately to some other VT again but
  329.   have to release Alt first.  In the other direction this should work:
  330.   the kernel always keeps track of the up/down status of all keys. (As
  331.   far as possible: on some keyboards some keys do not emit a scancode
  332.   when pressed (e.g.: the PFn keys of a FOCUS 9000) or released (e.g.:
  333.   the Pause key of many keyboards).)
  334.  
  335.   XFree86 1.3 saves the fonts loaded in the character ROMs when started,
  336.   and restores it on a console switch. Thus, the result of setfont on a
  337.   VT is wiped out when you go to X and back.  Using setfont under X will
  338.   lead to funny results.
  339.  
  340.   One can change under program control using the chvt command.
  341.  
  342.   7.1.  Changing the number of Virtual Consoles
  343.  
  344.   This question still comes up from time to time, but the answer is: you
  345.   already have enough of them.  Since kernel version 1.1.54, there are
  346.   between 1 and 63 virtual consoles. A new one is created as soon as it
  347.   is opened. It is removed by the utility disalloc (but it can be
  348.   removed only when no processes are associated to it anymore).
  349.  
  350.   For older kernels, change the line
  351.  
  352.   #define NR_CONSOLES     8
  353.  
  354.   in include/linux/tty.h (don't increase this number beyond 63), and
  355.   recompile the kernel. You might have to create the devices with
  356.   MAKEDEV or mknod ttyN c 4 N where N denotes the tty number.  If you
  357.   want the new VCs to run getty, add lines in /etc/inittab.
  358.  
  359.   When the consoles are allocated dynamically, it is usually easiest to
  360.   have only one or two running getty. More are opened by open -l -s
  361.   bash. Unused consoles (without associated processes) are disallocated
  362.   using disalloc.
  363.  
  364.   If you have spawn_login from kbd-0.90.tar.gz and you put
  365.  
  366.                loadkeys << EOF
  367.                alt keycode 103 = Spawn_Console
  368.                EOF
  369.                spawn_login &
  370.  
  371.   in /etc/rc.local, then typing Alt-UpArrow will create a fresh VC run¡
  372.   ning login (and switch to it). See also open-1.3.tgz.
  373.  
  374.   You can only login as "root" on terminals listed in /etc/securetty.
  375.  
  376.   8.  Ctrl-Alt-Del and other special key combinations
  377.  
  378.   8.1.  Ctrl-Alt-Del (Boot)
  379.  
  380.   If you press Ctrl-Alt-Del (or whatever key was assigned the keysym
  381.   Boot by loadkeys) then either the machine reboots immediately (without
  382.   sync), or init is sent a SIGINT. The former behaviour is the default.
  383.   The default can be changed by root, using the system call reboot(),
  384.   see ctrlaltdel(8).  Some init's change the default. What happens when
  385.   init gets SIGINT depends on the version of init used - often it will
  386.   be determined by the pf entry in /etc/inittab (which means that you
  387.   can run an arbitrary program in this case).  In the current kernel
  388.   Ctrl-AltGr-Del is no longer by default assigned to Boot.
  389.  
  390.   8.2.  Other combinations
  391.  
  392.   Name            Default binding
  393.   -------------------------------
  394.   Show_Memory     Shift-Scrollock
  395.   Show_Registers  AltGr-ScrollLock
  396.   Show_State      Ctrl-ScrollLock
  397.   Console_n       Alt-Fn and Ctrl-Alt-Fn  (1 <= n <= 12)
  398.   Console_{n+12}  AltGr-Fn                (1 <= n <= 12)
  399.   Incr_Console    Alt-RightArrow
  400.   Decr_Console    Alt-LeftArrow
  401.   Last_Console    Alt[Gr]-PrintScreen
  402.   Scroll_Backward Shift-PageUp
  403.   Scroll_Forward  Shift-PageDown
  404.   Caps_On                                 (CapsLock is a toggle; this key sets)
  405.   Compose         Ctrl-.
  406.  
  407.   8.3.  X Combinations
  408.  
  409.   Ctrl-Alt-Fn     Switch to VT n
  410.   Ctrl-Alt-KP+    Next mode
  411.   Ctrl-Alt-KP-    Previous mode
  412.   Ctrl-Alt-Backspace      Kill X
  413.  
  414.   On some motherboards, Ctrl-Alt-KP- and Ctrl-Alt-KP+ will be equivalent
  415.   to pressing the Turbo button. That is, both will produce the scancodes
  416.   1d 38 4a ca b8 9d and 1d 38 4e ce b8 9d, and both will switch between
  417.   Turbo (>= 25MHz) and non-Turbo (8 or 12 MHz).  (Often these key combi¡
  418.   nations only function this way when enabled by jumpers on the mother¡
  419.   board.)
  420.  
  421.   Perry F Nguyen (pfnguyen@netcom22.netcom.com) writes: AMI BIOS has a
  422.   feature that locks up the keyboard and flashes the LED's if the Ctrl-
  423.   Alt-Backspace combination is pressed while a BIOS password is enabled,
  424.   until the CMOS/BIOS password is typed in.
  425.  
  426.   8.4.  Dosemu Combinations
  427.  
  428.   Ctrl-Alt-Fn     Switch to VT n (from version 0.50; earlier Alt-Fn)
  429.   Ctrl-Alt-PgDn   Kill dosemu (when in RAW keyboard mode)
  430.   (and many other combinations - see the dosemu documentation)
  431.  
  432.   8.5.  Composing symbols
  433.  
  434.   One symbol may be constructed using several keystrokes.
  435.  
  436.   ╖  LeftAlt-press, followed by a decimal number typed on the keypad,
  437.      followed by LeftAlt-release, yields the symbol with code given by
  438.      this number.  (In Unicode mode this same mechanism, but then with 4
  439.      hexadecimal digits, may be used to define a Unicode symbol.)
  440.  
  441.   ╖  A dead diacritic followed by a symbol, yields that symbol adorned
  442.      with that diacritic. If the combination is undefined, both keys are
  443.      taken separately.  Which keys are dead diacritics is user-settable;
  444.      none is by default.  Five dead diacritics can be defined (using
  445.      loadkeys(1)): dead_grave, dead_acute, dead_circumflex, dead_tilde,
  446.      dead_diaeresis.  Precisely what this adorning means is also user-
  447.      settable: dead-diacritic, symbol is equivalent to Compose +
  448.      diacritic + symbol.
  449.  
  450.   ╖  Compose followed by two symbols yields a combination symbol. These
  451.      combinations are user-settable. Today there are 68 combinations
  452.      defined by default; you can see them by saying "dumpkeys | grep
  453.      compose".
  454.  
  455.   ╖  Then there are `Sticky' modifier keys (since 1.3.33). For example,
  456.      one can type ^C as SControl, C and Ctrl-Alt-BackSpace as SControl,
  457.      SAlt, BackSpace.
  458.  
  459.   Note that there are at least three such composition mechanisms:
  460.  
  461.   1. The Linux keyboard driver mechanism, used in conjunction with
  462.      loadkeys.
  463.  
  464.   2. The X mechanism - see X386keybd(1), later XFree86kbd(1).  Under
  465.      X11R6: edit /usr/X11R6/lib/X11/locale/iso8859-1/Compose.
  466.  
  467.   3. The emacs mechanism obtained by loading "iso-insert.el".
  468.  
  469.      For X the order of the two symbols is arbitrary: both Compose-,-c
  470.      and Compose-c-, yield a c-cedilla; for Linux and emacs only the
  471.      former sequence works by default. For X the list of compose
  472.      combinations is fixed. Linux and emacs are flexible.  The three
  473.      default lists are somewhat similar, but the details are different.
  474.  
  475.   9.  Various properties of the console
  476.  
  477.   See loadkeys(1), setleds(1), setmetamode(1) for the codes generated by
  478.   the various keys and the setting of leds when not under X. Under X,
  479.   see xmodmap(1).
  480.  
  481.   See setterm(1), kbdrate(8) for properties such as foreground and
  482.   background colors, screen blanking, character repeat rate when not
  483.   under X.  Under X, see xset(1), also for key click and bell volume.
  484.  
  485.   The file /etc/termcap defines the escape sequences used by many
  486.   programs addressing the console (or any other terminal). A more modern
  487.   version is found in /usr/lib/terminfo. (See terminfo(5). Terminfo
  488.   files are compiled by the terminfo compiler /usr/lib/terminfo/tic, see
  489.   tic(1).)
  490.  
  491.   (On my machine) /dev/console is a symbolic link to /dev/tty0, and the
  492.   kernel regards /dev/tty0 as a synonym for the current VT.  XFree86 1.3
  493.   changes the owner of /dev/tty0, but does not reset this after
  494.   finishing. Thus, dumpkeys might fail because someone else owns
  495.   /dev/tty0; in such a case you might run X first.
  496.  
  497.   10.  How to get out of raw mode
  498.  
  499.   If some program using K_RAW keyboard mode exits without restoring the
  500.   keyboard mode to K_XLATE, then it is difficult to do anything - not
  501.   even Ctrl-Alt-Del works. However, it is sometimes possible to avoid
  502.   hitting the reset button.  (And desirable as well: your users may get
  503.   angry if you kill their Hack game by rebooting; you might also damage
  504.   your file system.)  Easy solutions involve logging in from another
  505.   terminal or another machine and doing kbd_mode -a.  The procedure
  506.   below assumes that no X is running, that the display is in text mode,
  507.   and that you are at your bash prompt, that you are using a US keyboard
  508.   layout, and that your interrupt character is Ctrl-C.
  509.   Step 1. Start X.  As follows: press 2 (and don't release), press F12
  510.   (and don't release) and immediately afterwards press = . This starts
  511.   X.  (Explanation: if a key press produces keycode K, then the key
  512.   release produces keycode K+128. Probably your shell does not like
  513.   these high characters, so we avoid generating them by not releasing
  514.   any key.  However, we have to be quick, otherwise key repeat starts.
  515.   The digit 2 produces a Ctrl-C that discards previous junk, the F12
  516.   produces an X and the = a Return.)  Probably your screen will be grey
  517.   now, since no .xinitrc was specified.  However, Ctrl-Alt-Fn will work
  518.   and you can go to another VT.  (Ctrl-Alt-Backspace also works, but
  519.   that exits X, and gets you back into the previous state, which is not
  520.   what you want.)
  521.  
  522.   Step 2. Setup to change the keyboard mode.  (For example, by sleep 5;
  523.   kbd_mode -a.)
  524.  
  525.   Step 3. Leave X again.  Alt-Fx (often Alt-F7) brings you back to X,
  526.   and then Ctrl-Alt-Backspace exits X. Within 5 seconds your keyboard
  527.   will be usable again.
  528.  
  529.   If you want to prepare for the occasion, then make 215A301 (3 symbols)
  530.   an alias for kbd_mode -a.  Now just hitting = F7 = (3 symbols) will
  531.   return you to sanity.
  532.  
  533.   11.  The TERM variable
  534.  
  535.   Many programs use the TERM variable and the database /etc/termcap or
  536.   /usr/lib/terminfo/* to decide which strings to send for clear screen,
  537.   move cursor, etc., and sometimes also to decide which string is sent
  538.   by the users backspace key, function keys etc.  This value is first
  539.   set by the kernel (for the console).  Usually, this variable is re-set
  540.   by getty, using /etc/ttytype or the argument specified in
  541.   /etc/inittab.  Sometimes, it is also set in /etc/profile.
  542.  
  543.   Older systems use TERM=console or TERM=con80x25. Newer systems (with
  544.   ncurses 1.8.6) use the more specific TERM=linux or TERM=linux-80x25.
  545.   However, old versions of setterm test for TERM=con* and hence fail to
  546.   work with TERM=linux.
  547.  
  548.   Since kernel version 1.3.2, the kernel default for the console is
  549.   TERM=linux.
  550.  
  551.   If you have a termcap without entry for linux, add the word linux to
  552.   the entry for the console:
  553.  
  554.                console|con80x25|linux:\
  555.  
  556.   and make /usr/lib/terminfo/l/linux a copy of or symbolic link to
  557.   /usr/lib/terminfo/c/console.
  558.  
  559.   11.1.  Terminfo
  560.  
  561.   The terminfo entry for the linux console from ncurses 1.8.6 misses the
  562.   entry kich1=needed by some programs.  Edit the file and tic it.
  563.  
  564.   12.  How to make other programs work with non-ASCII chars
  565.  
  566.   In the bad old days this used to be quite a hassle. Every separate
  567.   program had to be convinced individually to leave your bits alone.
  568.   Not that all is easy now, but recently a lot of gnu utilities have
  569.   learned to react to LC_CTYPE=iso_8859_1 or LC_CTYPE=iso-8859-1.  Try
  570.   this first, and if it doesn't help look at the hints below.
  571.  
  572.   First of all, the 8-th bit should survive the kernel input processing,
  573.   so make sure to have stty cs8 -istrip -parenb set.
  574.  
  575.   A. For emacs, put lines
  576.  
  577.                (standard-display-european t)
  578.                (set-input-mode nil nil 1)
  579.                (require 'iso-syntax)
  580.  
  581.   and perhaps also
  582.  
  583.                (load-file "iso-insert.el")
  584.                (define-key global-map [?\C-.] 8859-1-map)
  585.  
  586.   into your $HOME/.emacs.  (The latter line will not work under xterm,
  587.   if you use emacs -nw, but in that case you can put
  588.  
  589.                XTerm*VT100.Translations:       #override\n\
  590.                Ctrl <KeyPress> . : string("\0308")
  591.  
  592.   in your .Xresources.)
  593.  
  594.   B. For less, put LESSCHARSET=latin1 in the environment.
  595.  
  596.   C. For ls, give the option -N. (Probably you want to make an alias.)
  597.  
  598.   D. For bash (version 1.13.*), put
  599.  
  600.                set meta-flag on
  601.                set convert-meta off
  602.  
  603.   and, according to the Danish HOWTO,
  604.  
  605.                set output-meta on
  606.  
  607.   into your $HOME/.inputrc.
  608.  
  609.   E. For tcsh, use
  610.  
  611.                setenv LANG     US_en
  612.                setenv LC_CTYPE iso_8859_1
  613.  
  614.   If you have nls on your system, then the corresponding routines are
  615.   used.  Otherwise tcsh will assume iso_8859_1, regardless of the values
  616.   given to LANG and LC_CTYPE. See the section NATIVE LANGUAGE SYSTEM in
  617.   tcsh(1).  (The Danish HOWTO says: setenv LC_CTYPE ISO-8859-1; stty
  618.   pass8)
  619.  
  620.   F. For flex, give the option -8 if the parser it generates must be
  621.   able to handle 8-bit input. (Of course it must.)
  622.  
  623.   G. For elm, set displaycharset to ISO-8859-1.  (Danish HOWTO: LANG=C
  624.   and LC_CTYPE=ISO-8859-1)
  625.  
  626.   H. For programs using curses (such as lynx) David Sibley reports: The
  627.   regular curses package uses the high-order bit for reverse video mode
  628.   (see flag _STANDOUT defined in /usr/include/curses.h).  However,
  629.   ncurses seems to be 8-bit clean and does display iso-latin-8859-1
  630.   correctly.
  631.  
  632.   I. For programs using groff (such as man), make sure to use -Tlatin1
  633.   instead of -Tascii. Old versions of the program man also use col, and
  634.   the next point also applies.
  635.  
  636.   J. For col, make sure 1) that it is fixed so as to do
  637.   setlocale(LC_CTYPE,""); and 2) to put LC_CTYPE=ISO-8859-1 in the
  638.   environment.
  639.  
  640.   K. For rlogin, use option -8.
  641.  
  642.   L. For joe,
  643.   sunsite.unc.edu:/pub/Linux/apps/editors/joe-1.0.8-linux.tar.gz is said
  644.   to work after editing the configuration file. Someone else said: joe:
  645.   Put the -asis option in /isr/lib/joerc in the first column.
  646.  
  647.   M. For LaTeX: ocumentstyle[isolatin]{article}.  For LaTeX2e:
  648.   ocumentclass{article}sepackage{isolatin} where isolatin.sty is
  649.   available from ftp://ftp.vlsivie.tuwien.ac.at/pub/8bit.
  650.  
  651.   A nice discussion on the topic of ISO-8859-1 and how to manage 8-bit
  652.   characters is contained in the file grasp.insa-
  653.   lyon.fr:/pub/faq/fr/accents (in French). Another fine discussion (in
  654.   English) can be found in rtfm.mit.edu:pub/usenet-by-
  655.   group/comp.answers/character-sets/iso-8859-1-faq.  And another(?), in
  656.   ftp.vlsivie.tuwien.ac.at:/pub/8bit/FAQ-ISO-8859-1.
  657.  
  658.   13.  What precisely does XFree86-2.1 do when it initializes its
  659.   keymap?
  660.  
  661.   Since version 2.1, XFree86 will initialize its keymap from the Linux
  662.   keymap, as far as possible. However, Linux had 16 entries per key (one
  663.   for each combination of the Shift, AltGr, Ctrl, Alt modifiers) and
  664.   presently has 256 entries per key, while X has 4 entries per key (one
  665.   for each combination of Shift, Mod), so some information is
  666.   necessarily lost.
  667.  
  668.   First X reads the Xconfig file, where definitions of the LeftAlt,
  669.   RightAlt, RightCtl, ScrollLock keys as Meta, ModeShift, Compose,
  670.   ModeLock or ScrollLock might be found - see X386keybd(1), later
  671.   XFree86kbd(1).
  672.  
  673.   For Mod the LeftAlt key is taken, unless RightCtl was defined as
  674.   ModeShift or ModeLock, in which case RightCtl is taken, or RightAlt
  675.   was so defined, in which case RightAlt is taken.  This determines how
  676.   the 4 XFree86 meanings of a key are selected from the 16 Linux
  677.   meanings.  Note that Linux today does not distinguish by default
  678.   between the two Ctrl keys or between the two Shift keys. X does
  679.   distinguish.
  680.  
  681.   Now the kernel keymap is read and the usually obvious corresponding X
  682.   bindings are made. The bindings for the "action keys" Show_Memory,
  683.   Show_State, Show_Registers, Last_Console, Console_n, Scroll_Backward,
  684.   Scroll_Forward, Caps_On and Boot are ignored, as are the dead
  685.   diacriticals, and the locks (except for ShiftLock), and the "ASCII-x"
  686.   keys.
  687.  
  688.   Next, the definitions in the Xconfig file are used. (Thus, a
  689.   definition of Compose in Xconfig will override its value as found in
  690.   the Linux keymap.)
  691.  
  692.   What happens to the strings associated with the function keys?
  693.   Nothing, X does not have such a concept. (But it is possible to define
  694.   strings for function keys in xterm - note however that the window
  695.   manager gets the keys first.)
  696.  
  697.   I don't know how to convince xterm that it should use the X keymap
  698.   when Alt is pressed; it seems just to look at its resource
  699.   eightBitInput, and depending on whether that is true or false either
  700.   set the high order bit of the character, or generate an additional
  701.   Escape character (just like setmetamode(1) does for the console).
  702.  
  703.   14.  Unusual keys and keyboards
  704.  
  705.   The two keys PrintScrn/SysRq and Pause/Break are special in that they
  706.   have two keycodes: the former has keycode 84 when Alt is pressed
  707.   simultaneously, and keycode 99 otherwise; the latter has keycode 101
  708.   when Ctrl is pressed simultaneously, and keycode 119 otherwise.
  709.   (Thus, it makes no sense to bind functions to Alt keycode 99 or Ctrl
  710.   keycode 119.)
  711.  
  712.   If you have strange keys, that do not generate any code under Linux
  713.   (or generate messages like "unrecognized scancode"), and your kernel
  714.   is 1.1.63 or later, then you can use setkeycodes(1) to tell the kernel
  715.   about them. They won't work under X, however.  Once they have gotten a
  716.   keycode from setkeycodes, they can be assigned a function by loadkeys.
  717.  
  718.   15.  Examples of use of loadkeys and xmodmap
  719.  
  720.   Switching Caps Lock and Control on the keyboard (assuming you use
  721.   keymaps 0-15; check with dumpkeys | head -1)
  722.  
  723.          % loadkeys
  724.          keymaps 0-15
  725.          keycode 58 = Control
  726.          keycode 29 = Caps_Lock
  727.          %
  728.  
  729.   Switching them under X only:
  730.  
  731.          % xmodmap .xmodmaprc
  732.  
  733.   where .xmodmaprc contains lines
  734.  
  735.          remove Lock = Caps_Lock
  736.          remove Control =  Control_L
  737.          keysym  Control_L  =  Caps_Lock
  738.          keysym  Caps_Lock  = Control_L
  739.          add Lock = Caps_Lock
  740.          add Control = Control_L
  741.  
  742.   What is this about the key numbering? Backspace is 14 under Linux, 22
  743.   under X?  Well, the numbering can best be regarded as arbitrary; the
  744.   Linux number of a key can be found using showkey(1), and the X number
  745.   using xev(1). Often the X number will be 8 more than the Linux number.
  746.  
  747.   15.1.  `I can use only one finger to type with'
  748.  
  749.   Can the Shift, Ctrl and Alt keys be made to behave as toggles?"  Yes,
  750.   after saying
  751.  
  752.        % loadkeys
  753.        keycode 29 = Control_Lock
  754.        keycode 42 = Shift_Lock
  755.        keycode 56 = Alt_Lock
  756.        %
  757.  
  758.   the left Control, Shift and Alt keys will act as toggles.  The numbers
  759.   involved are revealed by showkey (and usually are 29, 97, 42, 54, 56,
  760.   100 for left and right control, shift and alt, respectively), and the
  761.   functions are Control_Lock, Shift_Lock, Alt_Lock, ALtGr_Lock.
  762.  
  763.   What about `sticky' modifier keys?  Well, since their introduction in
  764.   the kernel (1.3.33) there has not been a new release of the kbd
  765.   package yet, so they have to be invoked using their hexadecimal codes.
  766.   For example,
  767.  
  768.        % loadkeys
  769.        keymaps 0-15
  770.        keycode 54 = 0x0c00
  771.        keycode 97 = 0x0c02
  772.        keycode 100 = 0x0c03
  773.        %
  774.  
  775.   will make the right Shift, Ctrl, Alt sticky versions of the left ones.
  776.  
  777.   16.  Changing the video mode
  778.  
  779.   As far as I know there are 6 ways to change resolution:
  780.  
  781.   1. At compile time: change the line
  782.  
  783.                SVGA_MODE=      -DSVGA_MODE=NORMAL_VGA
  784.  
  785.   in /usr/src/linux/Makefile.
  786.  
  787.   1A. After compilation: use rdev -v - a terrible hack, but it exists.
  788.  
  789.   2. At boot time: put vga=ask in the lilo config file, and lilo will
  790.   ask you what video mode you want. Once you know, put vga=mypreference.
  791.  
  792.   3. At run time: A. Use the resizecons command. (This is a very
  793.   primitive wrapper around the VT_RESIZE ioctl.)  B. Use the
  794.   SVGATextMode command. (This is a less primitive wrapper around the
  795.   VT_RESIZE ioctl.)
  796.  
  797.   4. Not "on the console": Under dosemu, or with svgalib etc. you can
  798.   change the hardware video mode without the console driver being aware
  799.   of it. Sometimes this is useful in getting resizecons or SVGATextMode
  800.   set up: use dosemu and some DOS program to get into the desired
  801.   videomode, dump (say from another VT) the contents of all video
  802.   hardware registers, and use that in the initialization that resizecons
  803.   and SVGATextMode require.  In some cases where the video mode has
  804.   gotten into some unusable state, starting dosemu, relying on the BIOS
  805.   to set up the video mode, and then killing dosemu (with kill -9), is
  806.   the easiest way to get into shape again.
  807.  
  808.   16.1.  Instructions for the use of resizecons
  809.  
  810.   Get svgalib and compile the program restoretextmode.  Boot up your
  811.   machine in all possible video modes (using vga=ask in the lilo config
  812.   file), and write the video hardware register contents to files CxR
  813.   (C=cols, R=rows), e.g., 80x25, 132x44, etc.  Put these files in
  814.   /usr/lib/kbd/videomodes.  Now resizecons 132x44 will change videomode
  815.   for you (and send SIGWINCH to all processes that need to know about
  816.   this, and load another font if necessary).
  817.  
  818.   At present, resizecons only succeeds when there is memory enough for
  819.   both the old and the new consoles at the same time.
  820.  
  821.   17.  Changing the keyboard repeat rate
  822.  
  823.   At startup, the Linux kernel sets the repeat rate to its maximal
  824.   value.  For most keyboards this is reasonable, but for some it means
  825.   that you can hardly touch a key without getting three copies of the
  826.   corresponding symbol. Use the program kbdrate(8) to change the repeat
  827.   rate, or, if that doesn't help, edit or remove the section
  828.  
  829.   ______________________________________________________________________
  830.        ! set the keyboard repeat rate to the max
  831.  
  832.            mov     ax,#0x0305
  833.            xor     bx,bx           ! clear bx
  834.            int     0x16
  835.   ______________________________________________________________________
  836.  
  837.   of /usr/src/linux/[arch/i386/]boot/setup.S.
  838.  
  839.   18.  Screensaving
  840.  
  841.   setterm -blank nn will tell the console driver to blank the screen
  842.   after nn minutes of inactivity. (With nn = 0, screensaving is turned
  843.   off. In some old kernels this first took effect after the next
  844.   keyboard interrupt.)
  845.  
  846.   The s option of xset(1) will set the X screensaving parameters.
  847.  
  848.   The video hardware powersaving modes can be enabled/disabled using the
  849.   setvesablank program given in the starting comment of
  850.   /usr/src/linux/drivers/char/vesa_blank.c.
  851.  
  852.   19.  Some properties of the VT100 - application key mode
  853.  
  854.   : Sometimes my curser keys produce strange codes?
  855.  
  856.   When the terminal is in application key mode the cursor keys produce
  857.   Esc O x  and otherwise  Esc [ x  where x is one of A,B,C,D.  Certain
  858.   programs put the terminal in application key mode; if you kill them
  859.   with kill -9, or if they crash, then the mode will not be reset.
  860.  
  861.           % echo -e '\033c'
  862.  
  863.   resets all properties of the current VC. Just changing the application
  864.   key mode is done by
  865.  
  866.           % echo -e '\033[?1h'
  867.  
  868.   (set) and
  869.  
  870.           % echo -e '\033[?1l'
  871.  
  872.   (clear).
  873.  
  874.   20.  Hardware incompatibility
  875.  
  876.   Several people have noticed that they lose typed characters when a
  877.   floppy disk is active. It seems that this might be a problem with
  878.   Uni-486WB motherboards.  (Please mail me to confirm [yes, I have the
  879.   same problem], deny [no, nothing wrong with my Uni-486WB], modify [My
  880.   Xyzzy machine has the same problem].)
  881.  
  882.   Some people experience sporadic lockups - sometimes associated to hard
  883.   disk activity or other I/O.
  884.  
  885.   ulf@rio70.bln.sni.de (Ulf Tietz) wrote: `I have had the same problems,
  886.   when I had my motherboard tuned too fast.  So I reset all the timings
  887.   ( CLK, wait statements etc ) to more conventional values, and the
  888.   problems are gone.'
  889.  
  890.   bhogan@crl.com (Bill Hogan) wrote: `If you have an AMI BIOS, you might
  891.   try setting the Gate A20 emulation parameter to 'chipset' (if you have
  892.   that option). Whenever I have had that parameter set to any of the
  893.   other options on my machine ('fast', 'both', 'disabled') I have had
  894.   frequent keyboard lockups.'
  895.  
  896.   --------------------------------------------------------------------
  897.  
  898.   Additions and corrections are welcome.  Andries Brouwer - aeb@cwi.nl
  899.  
  900.