home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  

UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 41.11 How termcap and terminfo Describe Terminals Chapter 41
Terminal and Serial Line Settings
Next: 42. Problems with Terminals

41.12 Finding Out What Characters Your Terminal's Special Keys Send

Sometimes, when writing vi keymaps ( 31.2 , 31.13 ) , you need to find out what characters are generated by labeled keys like arrows, HOME, and Function Keys.

If you have a terminal manual handy, the information should be listed somewhere in there. If not, you can read the termcap or terminfo entry ( 41.11 ) . Unfortunately, not every entry is complete - a terminal may have capabilities that aren't described in its entry. In any event, if you don't know the syntax well, finding the right information can be difficult.

However, there are several online techniques for finding out what character is sent by a special key. Each has drawbacks, but between them, you can almost always find out what character a key generates.

  • Enter insert mode in vi and use the ^V control sequence ( 31.6 ) to quote each special key. That is, type CTRL-v followed by the key whose identity you are trying to discover. A printable representation of the key should appear on the screen.

    This will not work if the key generates a sequence containing more than one non-printing character, since ^V will only quote the first one. It also will not work for keys that generate a newline (such as the down-arrow key on the Wyse-50 keyboard)-but in such a case, the action of the key should be obvious.

  • At the command line, print:

     -echo; cat -v; stty echo

    and then type the special keys, each followed by a carriage return. cat -v ( 25.7 ) will echo the translated version on the screen. When you are finished, type CTRL-d.

  • Simply type the special key at the shell prompt. As long as the key does not have a special meaning (for example, ^C to interrupt jobs or ^D for end of input), the command generated by the key will be executed on the terminal. Depending on the version of UNIX you use, a printable equivalent to the command generated by the key you pressed may also be printed as the command is executed. (Keep in mind that with full-duplex communications, characters are not sent from your keyboard directly to your terminal but are sent to the system and echoed back to the terminal.)

    On some systems, the control character is recognized on input and is echoed in two separate ways: as a printable representation of the control character (e.g., ^Z -literally, caret-Z) and as the actual control character. Other systems echo only the actual control character, which means that you see the effect but not the character that caused it.

    In either case, the shell will give an error message containing the character(s) typed as soon as you press RETURN. The message should read something like this:

    ^[[U : Command not found.

    If, on the other hand, the key generates a sequence that is meaningful to the device, some standard function, such as interrupt, end-of-file, or suspend, will be executed. You can find out what command invokes each of these functions using stty ( 41.3 ) .

- JS , TOR

Previous: 41.11 How termcap and terminfo Describe Terminals UNIX Power Tools Next: 42. Problems with Terminals
41.11 How termcap and terminfo Describe Terminals Book Index 42. Problems with Terminals

The UNIX CD Bookshelf Navigation The UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System