home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / A / KEYTBLS / _KEYTBLS.TAR / usr / doc / keytables / kbd.FAQ < prev    next >
Encoding:
Text File  |  1995-01-07  |  21.2 KB  |  498 lines

  1. kbd.FAQ - version of 940926
  2. -------------------------------------------------------------------------
  3. Contents
  4.  
  5.  0. Useful programs
  6.  1. Resetting your terminal
  7.  2. Delete and backspace
  8.  3. The console character sets (and what to do if your screen is garbled)
  9.  4. Console switching
  10.  5. Ctrl-Alt-Del and other special key combinations
  11.  6. Various properties of the console
  12.  7. How to get out of raw mode
  13.  8. How to make other programs work with non-ASCII chars
  14.  9. What precisely does XFree86-2.1 do when it initializes its keymap ?
  15. 10. Examples of use of loadkeys and xmodmap
  16. 11. Changing the number of Virtual Consoles
  17. 12. Changing the videomode
  18. -------------------------------------------------------------------------
  19. 0. Useful programs
  20.  
  21. The following packages contain keyboard or console related programs.
  22.  
  23. kbd-0.88.tar.gz contains loadkeys, dumpkeys, showkey, setmetamode,
  24.     setleds, setfont, showfont, mapscrn, kbd_mode, chvt, resize,
  25.     disalloc.
  26. shellutils-1.8 contains stty.
  27. utilb-1.3.taz contains setterm.
  28. utile-1.5.taz contains kbdrate.
  29. open-1.1.tgz contains open.
  30. The X distribution contains xmodmap, kbd_mode. (See also X386keybd(1).)
  31. -------------------------------------------------------------------------
  32. 1. Resetting your terminal
  33.  
  34. The command "reset" will reset the console driver. This helps when
  35. the screen is full of funny graphic characters, and also if it is
  36. reduced to the bottom line. If you don't have this command, or if it
  37. does something else, make your own:
  38.     #!/bin/sh
  39.     echo -e \\033c
  40. that is, you want to send the two characters Escape c to the console.
  41. If you loaded some strange font, and want to return to the default,
  42.     setfont
  43. will do (provided you stored the default font in the default place).
  44. On old terminals output involving tabs may require a dalay, and you
  45. have to say
  46.     stty tabs3
  47. (see stty(1)). You can change the video mode using resize. This
  48. usually settles the output side.
  49. On the input side there are many things that might be wrong. If X or
  50. some other program using raw mode crashed, your keyboard may still be
  51. in raw (or mediumraw) mode, and it is difficult to give commands.
  52. (See "How to get out of raw mode" below.)
  53.  
  54. -------------------------------------------------------------------------
  55. 2. Delete and backspace
  56.  
  57. A. How to tell Unix what character you want to use to delete the
  58. last typed character.
  59. % stty -erase ^?
  60.  
  61. If the character is erased, but in a funny way, then something is
  62. wrong with your tty settings. If echoprt is set, then erased characters
  63. are enclosed between \ and /. If echoe is not set, then the erase char
  64. is echoed (which is reasonable when it is a printing character, like #).
  65. Most people will want "stty echoe -echoprt". Saying "stty sane" will do
  66. this and more. Saying "stty -a" shows your current settings.
  67. How come this is not right by default? It is, if you use the right getty.
  68.  
  69. A1. "Getty used to do the right thing with delete and backspace
  70. but is broken now?"
  71. Earlier, the console driver would do BackSpace Space BackSpace (\010\040\010)
  72. when it got a Del (\177). Nowadays, Del's are ignored (as they should be,
  73. since the driver emulates a vt100). Get a better getty, i.e., one that does
  74. not output Del.
  75.  
  76. A2. "Login behaves differently at the first and second login attempts?"
  77. At the first attempt, you are talking to getty. At the second attempt,
  78. you are talking to login, a different program.
  79.  
  80. B. How to tell Linux what code to generate when any key is pressed.
  81. % loadkeys mykeys.map        (when not in (MEDIUM)RAW mode)
  82. % xmodmap mykeys.xmap        (under X)
  83. Note that XFree86-2.1 reads the Linux settings of the keymaps
  84. when initialising the X keymap. Although the two systems are not
  85. 100% compatible, this should mean that in many cases the use of
  86. xmodmap has become superfluous.
  87.  
  88. If, for example, you want your Backspace key to generate BackSpace
  89. (Control_h), instead of the default Delete, then
  90. % loadkeys
  91. keycode 14 = BackSpace
  92. %
  93. will do.
  94.  
  95. C. How to tell X to interchange Delete and Backspace.
  96. % xmodmap -e "keysym BackSpace = Delete" -e "keysym Delete = BackSpace" 
  97. Or, if you just want the Backspace key to generate a BackSpace:
  98. % xmodmap -e "keycode 22 = BackSpace"
  99.  
  100. D. How to tell emacs what to do when it receives a delete or backspace.
  101. Put in your .emacs file lines like
  102.   (global-set-key "\?" 'delete-backward-char)
  103.   (global-set-key "\C-h" 'help-command)
  104. Of course you can bind other commands to other keys in the same way.
  105.  
  106. E. How to tell emacs to interchange Delete and Backspace.
  107. Put in your .emacs file lines
  108.   (setq keyboard-translate-table (make-string 128 0))
  109.   (let ((i 0))
  110.   (while (< i 128)
  111.       (aset keyboard-translate-table i i)
  112.       (setq i (1+ i))))
  113.   (aset keyboard-translate-table ?\b ?\^?)
  114.   (aset keyboard-translate-table ?\^? ?\b)
  115.  
  116. F. How to tell kermit to interchange Delete and backspace.
  117. Put in your .kermrc file the lines
  118.   set key \127 \8
  119.   set key \8 \127
  120.  
  121. G. How to tell xterm about your favourite tty modes.
  122. Normally xterm will inherit the tty modes from its invoker.
  123. Under xdm, the default erase and kill characters are # and @,
  124. as in good old Unix Version 6.
  125. If you don't like that, you might put something like
  126.  
  127.   XTerm*ttymodes: erase ^? kill ^U intr ^C quit ^\ eof ^D susp ^Z start ^Q stop ^S eol ^@
  128.  
  129. in /usr/lib/X11/app-defaults/XTerm or in $HOME/.Xresources, assuming that
  130. you have a line
  131.  
  132.   xrdb $HOME/.Xresources
  133.  
  134. in your $HOME/.xinitrc .
  135.  
  136. H. What about termcap and terminfo?
  137. When people have problems with backspace, they tend to look at their termcap
  138. (or terminfo) entry for the terminal, and indeed, there does exist a kb
  139. (or kbs) capability describing the code generated by the Backspace key.
  140. However, not many programs use it, so unless you are having problems with one
  141. particular program only, probably the fault is elsewhere.
  142. Of course it is a good idea anyway to correct your termcap (terminfo) entry.
  143. ------------------------------------------------------------------------------
  144. 3. The console character sets
  145.  
  146. The kernel knows about 4 translations of bytes into console-screen symbols.
  147. The four tables are: a) Latin1 -> PC,  b) VT100 graphics -> PC, c) PC -> PC,
  148. d) user-defined.
  149.  
  150. There are two character sets, called G0 and G1, and one of them
  151. is the current character set. [Initially G0.] 
  152. Typing ^N causes G1 to become current, ^O causes G0 to become current.
  153.  
  154. These variables G0 and G1 point at a translation table, and can be changed
  155. by the user. Initially they point at tables a) and b), respectively.
  156. The sequences ESC ( B and ESC ( 0 and ESC ( U and ESC ( K cause G0 to point
  157. at translation table a), b), c) and d), respectively.
  158. The sequences ESC ) B and ESC ) 0 and ESC ) U and ESC ) K cause G1 to point
  159. at translation table a), b), c) and d), respectively.
  160.  
  161. The sequence ESC c causes a terminal reset, which is what you want if the
  162. screen is all garbled. The oft-advised "echo ^V^O" will only make G0 current,
  163. but there is no guarantee that G0 points at table a).
  164. In some distributions there is a program reset(1) that just does "echo ^[c".
  165. If your termcap entry for the console is correct (and has an entry :rs=\Ec:),
  166. then also "setterm -reset" will work.
  167.  
  168. The user-defined mapping table can be set using mapscrn(8).
  169. The result of the mapping is that if a symbol c is printed, the symbol
  170. s = map[c] is sent to the video memory. The bitmap that corresponds to
  171. s is found in the character ROM, and can be changed using setfont(8).
  172.  
  173. ------------------------------------------------------------------------------
  174. 4. Console switching
  175.  
  176. XFree86 1.3 does not know that Alt is down when you switch to the X
  177. window. Thus, you cannot switch immediately to some other VT again
  178. but have to release Alt first.
  179. In the other direction this should work: the kernel always keeps
  180. track of the up/down status of all keys. (As far as possible: on some
  181. keyboards some keys do not emit a scancode when pressed [e.g.: the PFn
  182. keys of a FOCUS 9000] or released [e.g.: the Pause key of many keyboards].)
  183.  
  184. XFree86 1.3 saves the fonts loaded in the character ROMs when started,
  185. and restores it on a console switch. Thus, the result of setfont on
  186. a VT is wiped out when you go to X and back.
  187.  
  188. ------------------------------------------------------------------------------
  189. 5. Ctrl-Alt-Del and other special key combinations
  190.  
  191. A. Ctrl-Alt-Del (Boot)
  192. If you press Ctrl-Alt-Del (or whatever key was assigned the keysym Boot by
  193. loadkeys) then either the machine reboots immediately (without sync), or
  194. init is sent a SIGINT. The former behaviour is the default. The default can
  195. be changed by root, using the system call reboot(), see ctrlaltdel(8).
  196. Some init's change the default. What happens when init gets SIGINT depends
  197. on the version of init used - often it will be determined by the pf entry
  198. in /etc/inittab [which means that you can run an arbitrary program in this case].
  199. In the current kernel Ctrl-AltGr-Del is no longer by default assigned to Boot.
  200.  
  201. B. Other combinations
  202.  
  203. Name        Default binding
  204. -------------------------------
  205. Show_Memory    Shift-Scrollock
  206. Show_Registers    AltGr-ScrollLock
  207. Show_State    Ctrl-ScrollLock
  208. Console_n    Alt-Fn            (1 <= n <= 12)
  209. Console_{n+12}    AltGr-Fn        (1 <= n <= 12)
  210. Last_Console    Alt[Gr]-PrintScreen
  211. Scroll_Backward    Shift-PageUp
  212. Scroll_Forward    Shift-PageDown
  213. Caps_On                    (CapsLock is a toggle; this key sets)
  214. Compose        Ctrl-.
  215.  
  216. C. X Combinations
  217.  
  218. Ctrl-Alt-Fn    Switch to VT n
  219. Ctrl-Alt-KP+    Next mode
  220. Ctrl-Alt-KP-    Previous mode
  221. Ctrl-Alt-Backspace    Kill X
  222.  
  223. On some motherboards, Ctrl-Alt-KP- and Ctrl-Alt-KP+ will be equivalent to
  224. pressing the Turbo button. That is, both will produce the scancodes
  225. 1d 38 4a ca b8 9d and 1d 38 4e ce b8 9d, and both will switch between
  226. Turbo (>= 25MHz) and non-Turbo (8 or 12 MHz).
  227.  
  228. D. Dosemu Combinations
  229.  
  230. Ctrl-Alt-Fn    Switch to VT n (from version 0.50; earlier Alt-Fn)
  231. Ctrl-Alt-PgDn    Kill dosemu (when in RAW keyboard mode)
  232. (and many other combinations - see the dosemu documentation)
  233.  
  234. E. Composing symbols.
  235.  
  236. One symbol may be constructed using several keystrokes.
  237. - LeftAlt-press, followed by a decimal number typed on the keypad, followed
  238.   by LeftAlt-release, yields the symbol with code given by this number.
  239. - A dead diacritic followed by a symbol, yields that symbol adorned with
  240.   that diacritic. If the combination is undefined, both keys are taken
  241.   separately.
  242.   Which keys are dead diacritics is user-settable; none is by default.
  243.   Five dead diacritics can be defined (using loadkeys(1)): dead_grave,
  244.   dead_acute, dead_circumflex, dead_tilde, dead_diaeresis.
  245.   Precisely what this adorning means is also user-settable:
  246.   dead-diacritic + symbol is equivalent to Compose + diacritic + symbol.
  247. - Compose followed by two symbols yields a combination symbol. These
  248.   combinations are user-settable. Today there are 68 combinations
  249.   defined by default; you can see them by saying "dumpkeys | grep compose".
  250.  
  251. Note that there are at least three such composition mechanisms:
  252. 1. The Linux keyboard driver mechanism, used in conjunction with loadkeys.
  253. 2. The X mechanism - see X386keybd(1), later XFree86kbd(1).
  254. 3. The emacs mechanism obtained by loading "iso-insert.el".
  255. For X the order of the two symbols is arbitrary: both Compose-,-c and
  256. Compose-c-, yield a c-cedilla; for Linux and emacs only the former sequence
  257. works by default. For X the list of compose combinations is fixed. Linux
  258. and emacs are flexible.
  259. The three default lists are somewhat similar, but the details are different.
  260. ------------------------------------------------------------------------------
  261. 6. Various properties of the console
  262.  
  263. See loadkeys(1), setleds(1), setmetamode(1) for the codes generated by the
  264. various keys and the setting of leds when not under X. Under X, see xmodmap(1).
  265.  
  266. See setterm(1), kbdrate(8) for properties such as foreground and background
  267. colors, screen blanking, character repeat rate when not under X.
  268. Under X, see xset(1), also for key click and bell volume.
  269.  
  270. The file /etc/termcap defines the escape sequences used by many programs
  271. addressing the console (or any other terminal). A more modern version is
  272. found in /usr/lib/terminfo. (See terminfo(5). Terminfo files are compiled
  273. by the terminfo compiler /usr/lib/terminfo/tic, see tic(1).)
  274.  
  275. (On my machine) /dev/console is a symbolic link to /dev/tty0, and the
  276. kernel regards /dev/tty0 as a synonym for the current vt.
  277. XFree86 1.3 changes the owner of /dev/tty0, but does not reset this after
  278. finishing. Thus, dumpkeys might fail because someone else owns /dev/tty0;
  279. in such a case you might run X first.
  280.  
  281. ------------------------------------------------------------------------------
  282. 7. How to get out of raw mode
  283.  
  284. If some program using K_RAW keyboard mode exits without restoring the keyboard
  285. mode to K_XLATE, then it is difficult to do anything - not even Ctrl-Alt-Del
  286. works. However, it is sometimes possible to avoid hitting the reset button.
  287. (And desirable as well: your users may get angry if you kill their Hack game
  288. by rebooting; you might also damage your file system.)
  289. Easy solutions involve logging in from another terminal or another machine
  290. and doing "kbd_mode -a".
  291. The procedure below assumes that no X is running, that the display is in
  292. text mode, and that you are at your bash prompt, that you are using a US
  293. keyboard layout, and that your interrupt character is Ctrl-C.
  294.  
  295. Step 1. Start X.
  296. As follows: press 2 (and don't release), press F12 (and don't release)
  297. and immediately afterwards press = . This starts X.
  298.   (Explanation: if a key press produces keycode K, then the key release
  299.   produces keycode K+128. Probably your shell does not like these high
  300.   characters, so we avoid generating them by not releasing any key.
  301.   However, we have to be quick, otherwise key repeat starts. The digit 2
  302.   produces a Ctrl-C that discards previous junk, the F12 produces an X
  303.   and the = a Return.)
  304. Probably your screen will be grey now, since no .xinitrc was specified.
  305. However, Ctrl-Alt-Fn will work and you can go to another VT.
  306. (Ctrl-Alt-Backspace also works, but that exits X, and gets you back into
  307. the previous state, which is not what you want.)
  308.  
  309. Step 2. Setup to change the keyboard mode.
  310. (For example, by "sleep 5; kbd_mode -a".)
  311.  
  312. Step 3. Leave X again.
  313. (Alt-Fx [often Alt-F7] brings you back to X, and then Ctrl-Alt-Backspace
  314. exits X.)
  315. Within 5 seconds your keyboard will be usable again.
  316.  
  317. If you want to prepare for the occasion, then make "\215A\201" (3 symbols) an
  318. alias for "kbd_mode -a". Now just hitting F7 and = will return you to sanity.
  319. ------------------------------------------------------------------------------
  320. 8. How to make other programs work with non-ASCII chars
  321.  
  322. First of all, the 8-th bit should survive the kernel input processing,
  323. so make sure to have stty cs8 -istrip set.
  324.  
  325. A. In emacs, put lines
  326.     (standard-display-european t)
  327.     (set-input-mode nil nil 1)
  328.     (require 'iso-syntax)
  329. and perhaps also
  330.     (load-file "iso-insert.el")
  331.     (define-key global-map [?\C-.] 8859-1-map)
  332. into your $HOME/.emacs.
  333. (The latter line will not work under xterm, if you use "emacs -nw", but in that
  334. case you can put
  335.     XTerm*VT100.Translations:       #override\n\
  336.         Ctrl <KeyPress> . : string("\0308")
  337. in your .Xresources.)
  338.  
  339. B. For less, put
  340.     LESSCHARSET=latin1
  341. in the environment.
  342.  
  343. C. For ls, give the option -N. (Probably you want to make an alias.)
  344.  
  345. D. For bash (version 1.13.*), put
  346.     set meta-flag on
  347.     set convert-meta off
  348. into your $HOME/.inputrc.
  349.  
  350. E. For tcsh, use
  351.     setenv LANG     US_en
  352.     setenv LC_CTYPE iso_8859_1
  353. If you have nls on your system, then the corresponding routines are used.
  354. Otherwise tcsh will assume iso_8859_1, regardless of the values given to
  355. LANG and LC_CTYPE. See the section NATIVE LANGUAGE SYSTEM in tcsh(1).
  356.  
  357. F. For flex, give the option -8 if the parser it generates must be
  358. able to handle 8-bit input.
  359.  
  360. G. For elm, set "displaycharset" to ISO-8859-1.
  361.  
  362. H. For programs using curses (such as lynx) David Sibley reports:
  363. The regular curses package uses the high-order bit for reverse video mode
  364. (see flag _STANDOUT defined in /usr/include/curses.h).  However, ncurses
  365. seems to be 8-bit clean and does display iso-latin-8859-1 correctly.
  366.  
  367. I. For programs using groff (such as man), make sure to use -Tlatin1
  368. instead of -Tascii. The program man also uses col, so the next point
  369. also applies.
  370.  
  371. J. For col, make sure 1) that col is fixed so as to do setlocale(LC_CTYPE,"");
  372. and 2) to put LC_CTYPE=ISO-8859-1 in the environment.
  373.  
  374. A nice discussion on the topic of ISO-8859-1 and how to manage 8-bit
  375. characters is contained in the file grasp.insa-lyon.fr:/pub/faq/fr/accents
  376. (in French). Another fine discussion (in English) can be found in
  377. rtfm.mit.edu:pub/usenet-by-group/comp.answers/character-sets/iso-8859-1-faq.
  378.  
  379. ------------------------------------------------------------------------------
  380. 9. What precisely does XFree86-2.1 do when it initializes its keymap ?
  381.  
  382. Since version 2.1, XFree86 will initialize its keymap from the Linux keymap,
  383. as far as possible. However, Linux has 16 entries per key (one for each
  384. combination of the Shift, AltGr, Ctrl, Alt modifiers), and X has 4 entries
  385. per key (one for each combination of Shift, Mod), so some information
  386. is lost.
  387.  
  388. First X reads the Xconfig file, where definitions of the LeftAlt, RightAlt,
  389. RightCtl, ScrollLock keys as Meta, ModeShift, Compose, ModeLock or ScrollLock
  390. might be found - see X386keybd(1), later XFree86kbd(1).
  391.  
  392. For Mod the LeftAlt key is taken, unless RightCtl was defined as ModeShift or
  393. ModeLock, in which case RightCtl is taken, or RightAlt was so defined, in which
  394. case RightAlt is taken.
  395. This determines how the 4 XFree86 meanings of a key are selected from the 16
  396. Linux meanings.
  397. Note that Linux today does not distinguish bewteen the two Ctrl keys or between
  398. the two Shift keys, but probably that will change. X does distinguish.
  399.  
  400. Now the kernel keymap is read and the usually obvious corresponding X
  401. bindings are made. The bindings for the "action keys" Show_Memory, Show_State,
  402. Show_Registers, Last_Console, Console_n, Scroll_Backward, Scroll_Forward,
  403. Caps_On and Boot are ignored, as are the dead diacriticals, and the locks
  404. (except for ShiftLock), and the "ASCII-x" keys.
  405.  
  406. Next, the definitions in the Xconfig file are used. (Thus, a definition
  407. of Compose in Xconfig will override its value as found in the Linux keymap.)
  408.  
  409. What happens to the strings associated with the function keys? Nothing,
  410. X does not have such a concept. (But it is possible to define strings
  411. for function keys in xterm - note however that the window manager gets the
  412. keys first.)
  413.  
  414. I don't know how to convince xterm that it should use the X keymap
  415. when Alt is pressed; it seems just to look at its resource eightBitInput,
  416. and depending on whether that is true or false either set the high order bit
  417. of the character, or generate an additional Escape character
  418. (just like setmetamode(1) does for the console).
  419. ------------------------------------------------------------------------------
  420. 10. Examples of use of loadkeys and xmodmap
  421.  
  422. Switching Caps Lock and Control on the keyboard:
  423. % loadkeys
  424. keycode  58 = Control
  425. keycode  29 = Caps_Lock
  426. %
  427.  
  428. Switching them under X only:
  429.   % xmodmap .xmodmaprc
  430. where .xmodmaprc contains lines
  431.   remove Lock = Caps_Lock
  432.   remove Control =  Control_L
  433.   keysym  Control_L  =  Caps_Lock
  434.   keysym  Caps_Lock  = Control_L
  435.   add Lock = Caps_Lock
  436.   add Control = Control_L
  437.  
  438. What is this about the key numbering? Backspace is 14 under Linux,
  439. 22 under X?  Well, the numbering can best be regarded as arbitrary;
  440. the Linux number of a key can be found using showkey(1), and the
  441. X number using xev(1). Often the X number will be 8 more than the
  442. Linux number.
  443.  
  444. 10A. "I can use only one finger to type with. Can the shift, ctrl
  445. and alt keys be made to behave as toggles?"
  446. Yes, after saying
  447. % loadkeys
  448. keycode 29 = Control_Lock
  449. keycode 42 = Shift_Lock
  450. keycode 56 = Alt_Lock
  451. %
  452. the left Control, Shift and Alt keys will act as toggles.
  453. The numbers involved are revealed by showkey
  454. (and usually are 29, 97, 42, 54, 56, 100 for left and right control,
  455. shift and alt, respectively), and the functions are
  456. Control_Lock, Shift_Lock, Alt_Lock, ALtGr_Lock.
  457.  
  458. ------------------------------------------------------------------------------
  459. 11. Changing the number of Virtual Consoles
  460.  
  461. If you have applied my patch for dynamic allocation of VCs, then
  462. there are between 1 and 63 virtual consoles. A new one is created
  463. as soon as it is opened. It is removed by the utility disalloc
  464. (but it can be removed only when no processes are associated to it
  465. anymore).
  466.  
  467. Otherwise, change the line
  468. #define NR_CONSOLES     8
  469. in include/linux/tty.h (don't increase this number beyond 63),
  470. and recompile the kernel. You might have to create the devices
  471. with MAKEDEV or "mknod tty<tty-number> c 4 <tty-number>".
  472. If you want the new VCs to run getty, add lines in /etc/inittab.
  473.  
  474. When the consoles are allocated dynamically, it is usually easiest
  475. to have only one or two running getty. More are opened by
  476. "open -l -s bash". Unused consoles (without associated processes)
  477. are disallocated using "disalloc".
  478.  
  479. ------------------------------------------------------------------------------
  480. 12. Changing the video mode
  481.  
  482. Get svgalib and compile the program restoretextmode.
  483. Boot up your machine in all possible video modes
  484. (using vga=ask in the lilo config file), and write
  485. the video hardware register contents to files RxC
  486. (R=rows, C=cols), e.g., 25x80, 44x132, etc.
  487. Put these files in /usr/lib/kbd/videomodes.
  488. Now "resize 44x132" will change videomode for you
  489. (and send SIGWINCH to all processes that need to know
  490. about this, and load another font if necessary).
  491.  
  492. At present, resize only succeeds when there is memory enough
  493. for both the old and the new consoles at the same time.
  494.  
  495. ------------------------------------------------------------------------------
  496. Additions and corrections are welcome.
  497. Andries Brouwer - aeb@cwi.nl
  498.