home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 May / Chip_2000-05_cd1.bin / zkuste / Perl / ActivePerl-5.6.0.613.msi / 䆊䌷䈹䈙䏵-䞅䞆䞀㡆䞃䄦䠥 / _67aa6a9b5fc01575b92fef373e2332b6 < prev    next >
Text File  |  2000-03-23  |  10KB  |  240 lines

  1.  
  2. <HTML>
  3. <HEAD>
  4. <TITLE>Term::ReadKey - A perl module for simple terminal control</TITLE>
  5. <LINK REL="stylesheet" HREF="../../../Active.css" TYPE="text/css">
  6. <LINK REV="made" HREF="mailto:">
  7. </HEAD>
  8.  
  9. <BODY>
  10. <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
  11. <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
  12. <STRONG><P CLASS=block> Term::ReadKey - A perl module for simple terminal control</P></STRONG>
  13. </TD></TR>
  14. </TABLE>
  15.  
  16. <A NAME="__index__"></A>
  17. <!-- INDEX BEGIN -->
  18.  
  19. <UL>
  20.  
  21.     <LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
  22.  
  23.     <LI><A HREF="#synopsis">SYNOPSIS</A></LI>
  24.     <LI><A HREF="#description">DESCRIPTION</A></LI>
  25.     <LI><A HREF="#author">AUTHOR</A></LI>
  26. </UL>
  27. <!-- INDEX END -->
  28.  
  29. <HR>
  30. <P>
  31. <H1><A NAME="name">NAME</A></H1>
  32. <P>Term::ReadKey - A perl module for simple terminal control</P>
  33. <P>
  34. <HR>
  35. <H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
  36. <UL>
  37. <LI>Linux</LI>
  38. <LI>Solaris</LI>
  39. <LI>Windows</LI>
  40. </UL>
  41. <HR>
  42. <H1><A NAME="synopsis">SYNOPSIS</A></H1>
  43. <PRE>
  44.         use Term::ReadKey;
  45.         ReadMode 4; # Turn off controls keys
  46.         while (not defined ($key = ReadKey(-1)) {
  47.                 # No key yet
  48.         }
  49.         print "Get key $key\n";
  50.         ReadMode 0; # Reset tty mode before exiting</PRE>
  51. <P>
  52. <HR>
  53. <H1><A NAME="description">DESCRIPTION</A></H1>
  54. <P>Term::ReadKey is a compiled perl module dedicated to providing simple
  55. control over terminal driver modes (cbreak, raw, cooked, etc.,) support for
  56. non-blocking reads, if the architecture allows, and some generalized handy
  57. functions for working with terminals. One of the main goals is to have the
  58. functions as portable as possible, so you can just plug in ``use
  59. Term::ReadKey'' on any architecture and have a good likelyhood of it working.</P>
  60. <DL>
  61. <DT><STRONG><A NAME="item_ReadMode_MODE_%5B%2C_Filehandle%5D">ReadMode MODE [, Filehandle]</A></STRONG><BR>
  62. <DD>
  63. Takes an integer argument, which can currently be one of the following 
  64. values:
  65. <PRE>
  66.     0    Restore original settings.
  67.     1    Change to cooked mode.
  68.     2    Change to cooked mode with echo off. 
  69.           (Good for passwords)
  70.     3    Change to cbreak mode.
  71.     4    Change to raw mode.
  72.     5    Change to ultra-raw mode. 
  73.           (LF to CR/LF translation turned off) 
  74. </PRE>
  75. <PRE>
  76.  
  77.     Or, you may use the synonyms:</PRE>
  78. <PRE>
  79.  
  80.     restore
  81.     normal
  82.     noecho
  83.     cbreak
  84.     raw
  85.     ultra-raw</PRE>
  86. <P>These functions are automatically applied to the STDIN handle if no other
  87. handle is supplied. Modes 0 and 5 have some special properties worth
  88. mentioning: not only will mode 0 restore original settings, but it cause the
  89. next ReadMode call to save a new set of default settings. Mode 5 is similar
  90. to mode 4, except no CR/LF translation is performed, and if possible, parity
  91. will be disabled (only if not being used by the terminal, however. It is no different
  92. from mode 4 under Windows.)</P>
  93. <P>If you are executing another program that may be changing the terminal mode,
  94. you will either want to say</P>
  95. <PRE>
  96.     ReadMode 1
  97.     system('someprogram');
  98.     ReadMode 1;
  99. </PRE>
  100. <PRE>
  101.  
  102. which resets the settings after the program has run, or:</PRE>
  103. <PRE>
  104.     $somemode=1;
  105.     ReadMode 0;
  106.     system('someprogram');
  107.     ReadMode 1;
  108. </PRE>
  109. <PRE>
  110.  
  111. which records any changes the program may have made, before resetting the
  112. mode.</PRE>
  113. <P></P>
  114. <DT><STRONG><A NAME="item_ReadKey_MODE_%5B%2C_Filehandle%5D">ReadKey MODE [, Filehandle]</A></STRONG><BR>
  115. <DD>
  116. Takes an integer argument, which can currently be one of the following 
  117. values:
  118. <PRE>
  119.     0    Perform a normal read using getc
  120.     -1   Perform a non-blocked read
  121.     >0   Perform a timed read</PRE>
  122. <P>(If the filehandle is not supplied, it will default to STDIN.) If there is
  123. nothing waiting in the buffer during a non-blocked read, then undef will be
  124. returned. Note that if the OS does not provide any known mechanism for
  125. non-blocking reads, then a <CODE>ReadKey -1</CODE> can die with a fatal error. This
  126. will hopefully not be common.</P>
  127. <P>If MODE is greater then zero, then ReadKey will use it as a timeout value in
  128. seconds (fractional seconds are allowed), and won't return <A HREF="../../../lib/Pod/perlfunc.html#item_undef"><CODE>undef</CODE></A> until
  129. that time expires. (Note, again, that some OS's may not support this timeout
  130. behaviour.) If MODE is less then zero, then this is treated as a timeout
  131. of zero, and thus will return immediately if no character is waiting. A MODE
  132. of zero, however, will act like a normal getc.</P>
  133. <P>There are currently some limitations with this call under Windows. It may be
  134. possible that non-blocking reads will fail when reading repeating keys from
  135. more then one console.</P>
  136. <P></P>
  137. <DT><STRONG><A NAME="item_ReadLine_MODE_%5B%2C_Filehandle%5D">ReadLine MODE [, Filehandle]</A></STRONG><BR>
  138. <DD>
  139. Takes an integer argument, which can currently be one of the following 
  140. values:
  141. <PRE>
  142.     0    Perform a normal read using scalar(<FileHandle>)
  143.     -1   Perform a non-blocked read
  144.     >0   Perform a timed read</PRE>
  145. <P>If there is nothing waiting in the buffer during a non-blocked read, then
  146. undef will be returned. Note that if the OS does not provide any known
  147. mechanism for non-blocking reads, then a <CODE>ReadLine 1</CODE> can die with a fatal
  148. error. This will hopefully not be common. Note that a non-blocking test is
  149. only performed for the first character in the line, not the entire line.
  150. This call will probably <STRONG>not</STRONG> do what you assume, especially with
  151. ReadMode's higher then 1. For example, pressing Space and then Backspace
  152. would appear to leave you where you started, but any timeouts would now
  153. be suspended.</P>
  154. <P>This call is currently not available under Windows.</P>
  155. <P></P>
  156. <DT><STRONG><A NAME="item_GetTerminalSize_%5BFilehandle%5D">GetTerminalSize [Filehandle]</A></STRONG><BR>
  157. <DD>
  158. Returns either an empty array if this operation is unsupported, or a four
  159. element array containing: the width of the terminal in characters, the
  160. height of the terminal in character, the width in pixels, and the height in
  161. pixels. (The pixel size will only be valid in some environments.)
  162. <P>Under Windows, this function must be called with an ``output'' filehandle,
  163. such as STDOUT, or a handle opened to CONOUT$.</P>
  164. <P></P>
  165. <DT><STRONG><A NAME="item_SetTerminalSize_WIDTH%2CHEIGHT%2CXPIX%2CYPIX_%5B%2">SetTerminalSize WIDTH,HEIGHT,XPIX,YPIX [, Filehandle]</A></STRONG><BR>
  166. <DD>
  167. Return -1 on failure, 0 otherwise. Note that this terminal size is only for
  168. <STRONG>informative</STRONG> value, and changing the size via this mechanism will <STRONG>not</STRONG>
  169. change the size of the screen. For example, XTerm uses a call like this when
  170. it resizes the screen. If any of the new measurements vary from the old, the
  171. OS will probably send a SIGWINCH signal to anything reading that tty or pty.
  172. <P>This call does not work under Windows.</P>
  173. <P></P>
  174. <DT><STRONG><A NAME="item_GetSpeeds_%5B%2C_Filehandle%5D">GetSpeeds [, Filehandle]</A></STRONG><BR>
  175. <DD>
  176. Returns either an empty array if the operation is unsupported, or a two
  177. value array containing the terminal in and out speeds, in <STRONG>decimal</STRONG>. E.g,
  178. an in speed of 9600 baud and an out speed of 4800 baud would be returned as
  179. (9600,4800). Note that currently the in and out speeds will always be
  180. identical in some OS's. No speeds are reported under Windows.
  181. <P></P>
  182. <DT><STRONG><A NAME="item_GetControlChars_%5B%2C_Filehandle%5D">GetControlChars [, Filehandle]</A></STRONG><BR>
  183. <DD>
  184. Returns an array containing key/value pairs suitable for a hash. The pairs
  185. consist of a key, the name of the control character/signal, and the value
  186. of that character, as a single character. This call does nothing under Windows.
  187. <P>Each key will be an entry from the following list:</P>
  188. <PRE>
  189.         DISCARD
  190.         DSUSPEND
  191.         EOF
  192.         EOL
  193.         EOL2
  194.         ERASE
  195.         ERASEWORD
  196.         INTERRUPT
  197.         KILL
  198.         MIN
  199.         QUIT
  200.         QUOTENEXT
  201.         REPRINT
  202.         START
  203.         STATUS
  204.         STOP
  205.         SUSPEND
  206.         SWITCH
  207.         TIME</PRE>
  208. <P>Thus, the following will always return the current interrupt character,
  209. regardless of platform.</P>
  210. <PRE>
  211.         %keys = GetControlChars;
  212.         $int = $keys{INTERRUPT};</PRE>
  213. <P></P>
  214. <DT><STRONG><A NAME="item_SetControlChars_%5B%2C_Filehandle%5D">SetControlChars [, Filehandle]</A></STRONG><BR>
  215. <DD>
  216. Takes an array containing key/value pairs, as a hash will produce. The pairs
  217. should consist of a key that is the name of a legal control
  218. character/signal, and the value should be either a single character, or a
  219. number in the range 0-255. SetControlChars will die with a runtime error if
  220. an invalid character name is passed or there is an error changing the
  221. settings. The list of valid names is easily available via
  222. <PRE>
  223.         %cchars = GetControlChars();
  224.         @cnames = keys %cchars;</PRE>
  225. <P>This call does nothing under Windows.</P>
  226. <P></P></DL>
  227. <P>
  228. <HR>
  229. <H1><A NAME="author">AUTHOR</A></H1>
  230. <P>Kenneth Albanowski <<A HREF="mailto:kjahds@kjahds.com">kjahds@kjahds.com</A>></P>
  231. <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
  232. <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
  233. <STRONG><P CLASS=block> Term::ReadKey - A perl module for simple terminal control</P></STRONG>
  234. </TD></TR>
  235. </TABLE>
  236.  
  237. </BODY>
  238.  
  239. </HTML>
  240.