home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 13 / CDA13.ISO / DOC / HOWTO / OTHER_FO / SGML / KEYBOARD.GZ / Keyboard-HOWTO.sgml
Encoding:
SGML Document  |  1996-02-11  |  36.9 KB  |  919 lines

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