⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch41_12.htm

📁 the unix power tools
💻 HTM
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 41] 41.12 Finding Out What Characters Your Terminal's Special Keys Send</TITLE><METANAME="DC.title"CONTENT="UNIX Power Tools"><METANAME="DC.creator"CONTENT="Jerry Peek, Tim O'Reilly &amp; Mike Loukides"><METANAME="DC.publisher"CONTENT="O'Reilly &amp; Associates, Inc."><METANAME="DC.date"CONTENT="1998-08-04T21:52:13Z"><METANAME="DC.type"CONTENT="Text.Monograph"><METANAME="DC.format"CONTENT="text/html"SCHEME="MIME"><METANAME="DC.source"CONTENT="1-56592-260-3"SCHEME="ISBN"><METANAME="DC.language"CONTENT="en-US"><METANAME="generator"CONTENT="Jade 1.1/O'Reilly DocBook 3.0 to HTML 4.0"><LINKREV="made"HREF="mailto:online-books@oreilly.com"TITLE="Online Books Comments"><LINKREL="up"HREF="ch41_01.htm"TITLE="41. Terminal and Serial Line Settings"><LINKREL="prev"HREF="ch41_11.htm"TITLE="41.11 How termcap and terminfo Describe Terminals "><LINKREL="next"HREF="ch42_01.htm"TITLE="42. Problems with Terminals"></HEAD><BODYBGCOLOR="#FFFFFF"TEXT="#000000"><DIVCLASS="htmlnav"><H1><IMGSRC="gifs/smbanner.gif"ALT="UNIX Power Tools"USEMAP="#srchmap"BORDER="0"></H1><MAPNAME="srchmap"><AREASHAPE="RECT"COORDS="0,0,466,58"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="467,0,514,18"HREF="jobjects/fsearch.htm"ALT="Search this book"></MAP><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch41_11.htm"TITLE="41.11 How termcap and terminfo Describe Terminals "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 41.11 How termcap and terminfo Describe Terminals "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 41<BR>Terminal and Serial Line Settings</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="CHAPTER"HREF="ch42_01.htm"TITLE="42. Problems with Terminals"><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 42. Problems with Terminals"BORDER="0"></A></TD></TR></TABLE>&nbsp;<HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-0080">41.12 Finding Out What Characters Your Terminal's Special Keys Send</A></H2><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-46431"></A><ACLASS="indexterm"NAME="AUTOID-46434"></A><ACLASS="indexterm"NAME="AUTOID-46436"></A>Sometimes, when <SPANCLASS="link">writing <EMCLASS="emphasis">vi</EM> keymaps (<ACLASS="linkend"HREF="ch31_02.htm"TITLE="Save Time and Typing with the vi map Commands ">31.2</A>, <ACLASS="linkend"HREF="ch31_13.htm"TITLE="Making Cursor Keys Work in vi Text-input Mode ">31.13</A>)</SPAN>,you need to find out what characters are generated bylabeled keys like arrows,HOME,and Function Keys.</P><PCLASS="para">If you have a terminal manual handy, the information should be listedsomewhere in there.If not, you can <SPANCLASS="link">read the <EMCLASS="emphasis">termcap</EM> or <EMCLASS="emphasis">terminfo</EM> entry (<ACLASS="linkend"HREF="ch41_11.htm"TITLE="How termcap and terminfo Describe Terminals ">41.11</A>)</SPAN>.Unfortunately, not every entry is complete&nbsp;- a terminal may havecapabilities that aren't described in its entry.In any event, if you don't know the syntax well, finding the rightinformation can be difficult.</P><PCLASS="para">However,there are several online techniques for finding out what character is sent bya special key. Each has drawbacks, but between them,you can almost always find out what character a key generates. </P><ULCLASS="itemizedlist"><LICLASS="listitem"><PCLASS="para">Enter insert mode in <EMCLASS="emphasis">vi</EM> anduse the<SPANCLASS="link"><CODECLASS="literal">^V</CODE> control sequence (<ACLASS="linkend"HREF="ch31_06.htm"TITLE="Protecting Keys from Interpretation by ex ">31.6</A>)</SPAN>to quote each special key.That is, typeCTRL-vfollowed by the key whose identity you aretrying to discover. A printable representation of the key should appear on the screen.</P><PCLASS="para">This will not work if the key generates a sequencecontaining more than one non-printing character, since ^Vwill only quote the first one. It also will not work forkeys that generate a newline (such as the down-arrow key onthe Wyse-50 keyboard)-but in such a case, the action of thekey should be obvious.</P></LI><LICLASS="listitem"><PCLASS="para">At the command line, print:</P><PCLASS="para"><TABLECLASS="screen.co"BORDER="1"><TR><THVALIGN="TOP"><PRECLASS="calloutlist"><ACLASS="co"HREF="ch41_03.htm"TITLE="41.3 Find Out Terminal Settings with stty ">stty</A> </PRE></TH><TDVALIGN="TOP"><PRECLASS="screen">% <CODECLASS="userinput"><B>stty</B></CODE><CODECLASS="userinput"><B> -echo; cat -v; stty echo</B></CODE></PRE></TD></TR></TABLE></P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-46461"></A>and then type the special keys, each followed by a carriage return.<SPANCLASS="link"><EMCLASS="emphasis">cat -v</EM> (<ACLASS="linkend"HREF="ch25_07.htm"TITLE="Show Non-Printing Characters with cat -v or od -c ">25.7</A>)</SPAN>will echo the translated version on the screen. When youare finished, typeCTRL-d.</P></LI><LICLASS="listitem"><PCLASS="para">Simply type the special key at the shell prompt.As long as the key does not have a special meaning (for example,<CODECLASS="literal">^C</CODE> to interrupt jobs or <CODECLASS="literal">^D</CODE> for end of input),the command generated by the key will be executedon 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 yourterminal but are sent to the system and echoed back to the terminal.)</P><PCLASS="para">On some systems, the control character is recognized oninput and is echoed in two separate ways: as a printable representation of the control character (e.g.,<CODECLASS="literal">^Z</CODE>-literally, caret-Z) and as the actual controlcharacter. Other systems echo only the actual controlcharacter, which means that you see the effect but not thecharacter that caused it.</P><PCLASS="para">In either case, the shell will give an error message containing the character(s)typed as soon as you pressRETURN.The message should read something like this: </P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">^[[U : Command not found.</PRE></BLOCKQUOTE></P><PCLASS="para">If, on the other hand, the key generates a sequence that is meaningful to thedevice, some standard function, such as interrupt,end-of-file, or suspend, will be executed. You can find outwhat command invokes each of these functions using<SPANCLASS="link"><EMCLASS="emphasis">stty</EM> (<ACLASS="linkend"HREF="ch41_03.htm"TITLE="Find Out Terminal Settings with stty ">41.3</A>)</SPAN>.</P></LI></UL><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">JS</SPAN>, <SPANCLASS="authorinitials">TOR</SPAN></P></DIV></DIV><DIVCLASS="htmlnav"><P></P><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch41_11.htm"TITLE="41.11 How termcap and terminfo Describe Terminals "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 41.11 How termcap and terminfo Describe Terminals "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="book"HREF="index.htm"TITLE="UNIX Power Tools"><IMGSRC="gifs/txthome.gif"SRC="gifs/txthome.gif"ALT="UNIX Power Tools"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="CHAPTER"HREF="ch42_01.htm"TITLE="42. Problems with Terminals"><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 42. Problems with Terminals"BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">41.11 How termcap and terminfo Describe Terminals </TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="index"HREF="index/idx_0.htm"TITLE="Book Index"><IMGSRC="gifs/index.gif"SRC="gifs/index.gif"ALT="Book Index"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172">42. Problems with Terminals</TD></TR></TABLE><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><IMGSRC="gifs/smnavbar.gif"SRC="gifs/smnavbar.gif"USEMAP="#map"BORDER="0"ALT="The UNIX CD Bookshelf Navigation"><MAPNAME="map"><AREASHAPE="RECT"COORDS="0,0,73,21"HREF="../index.htm"ALT="The UNIX CD Bookshelf"><AREASHAPE="RECT"COORDS="74,0,163,21"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="164,0,257,21"HREF="../unixnut/index.htm"ALT="UNIX in a Nutshell"><AREASHAPE="RECT"COORDS="258,0,321,21"HREF="../vi/index.htm"ALT="Learning the vi Editor"><AREASHAPE="RECT"COORDS="322,0,378,21"HREF="../sedawk/index.htm"ALT="sed &amp; awk"><AREASHAPE="RECT"COORDS="379,0,438,21"HREF="../ksh/index.htm"ALT="Learning the Korn Shell"><AREASHAPE="RECT"COORDS="439,0,514,21"HREF="../lrnunix/index.htm"ALT="Learning the UNIX Operating System"></MAP></DIV></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -