home *** CD-ROM | disk | FTP | other *** search
-
- <HTML>
- <HEAD>
- <TITLE>Term::ReadKey - A perl module for simple terminal control</TITLE>
- <LINK REL="stylesheet" HREF="../../../Active.css" TYPE="text/css">
- <LINK REV="made" HREF="mailto:">
- </HEAD>
-
- <BODY>
- <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
- <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
- <STRONG><P CLASS=block> Term::ReadKey - A perl module for simple terminal control</P></STRONG>
- </TD></TR>
- </TABLE>
-
- <A NAME="__index__"></A>
- <!-- INDEX BEGIN -->
-
- <UL>
-
- <LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
-
- <LI><A HREF="#synopsis">SYNOPSIS</A></LI>
- <LI><A HREF="#description">DESCRIPTION</A></LI>
- <LI><A HREF="#author">AUTHOR</A></LI>
- </UL>
- <!-- INDEX END -->
-
- <HR>
- <P>
- <H1><A NAME="name">NAME</A></H1>
- <P>Term::ReadKey - A perl module for simple terminal control</P>
- <P>
- <HR>
- <H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
- <UL>
- <LI>Linux</LI>
- <LI>Solaris</LI>
- <LI>Windows</LI>
- </UL>
- <HR>
- <H1><A NAME="synopsis">SYNOPSIS</A></H1>
- <PRE>
- use Term::ReadKey;
- ReadMode 4; # Turn off controls keys
- while (not defined ($key = ReadKey(-1)) {
- # No key yet
- }
- print "Get key $key\n";
- ReadMode 0; # Reset tty mode before exiting</PRE>
- <P>
- <HR>
- <H1><A NAME="description">DESCRIPTION</A></H1>
- <P>Term::ReadKey is a compiled perl module dedicated to providing simple
- control over terminal driver modes (cbreak, raw, cooked, etc.,) support for
- non-blocking reads, if the architecture allows, and some generalized handy
- functions for working with terminals. One of the main goals is to have the
- functions as portable as possible, so you can just plug in ``use
- Term::ReadKey'' on any architecture and have a good likelyhood of it working.</P>
- <DL>
- <DT><STRONG><A NAME="item_ReadMode_MODE_%5B%2C_Filehandle%5D">ReadMode MODE [, Filehandle]</A></STRONG><BR>
- <DD>
- Takes an integer argument, which can currently be one of the following
- values:
- <PRE>
- 0 Restore original settings.
- 1 Change to cooked mode.
- 2 Change to cooked mode with echo off.
- (Good for passwords)
- 3 Change to cbreak mode.
- 4 Change to raw mode.
- 5 Change to ultra-raw mode.
- (LF to CR/LF translation turned off)
- </PRE>
- <PRE>
-
- Or, you may use the synonyms:</PRE>
- <PRE>
-
- restore
- normal
- noecho
- cbreak
- raw
- ultra-raw</PRE>
- <P>These functions are automatically applied to the STDIN handle if no other
- handle is supplied. Modes 0 and 5 have some special properties worth
- mentioning: not only will mode 0 restore original settings, but it cause the
- next ReadMode call to save a new set of default settings. Mode 5 is similar
- to mode 4, except no CR/LF translation is performed, and if possible, parity
- will be disabled (only if not being used by the terminal, however. It is no different
- from mode 4 under Windows.)</P>
- <P>If you are executing another program that may be changing the terminal mode,
- you will either want to say</P>
- <PRE>
- ReadMode 1
- system('someprogram');
- ReadMode 1;
- </PRE>
- <PRE>
-
- which resets the settings after the program has run, or:</PRE>
- <PRE>
- $somemode=1;
- ReadMode 0;
- system('someprogram');
- ReadMode 1;
- </PRE>
- <PRE>
-
- which records any changes the program may have made, before resetting the
- mode.</PRE>
- <P></P>
- <DT><STRONG><A NAME="item_ReadKey_MODE_%5B%2C_Filehandle%5D">ReadKey MODE [, Filehandle]</A></STRONG><BR>
- <DD>
- Takes an integer argument, which can currently be one of the following
- values:
- <PRE>
- 0 Perform a normal read using getc
- -1 Perform a non-blocked read
- >0 Perform a timed read</PRE>
- <P>(If the filehandle is not supplied, it will default to STDIN.) If there is
- nothing waiting in the buffer during a non-blocked read, then undef will be
- returned. Note that if the OS does not provide any known mechanism for
- non-blocking reads, then a <CODE>ReadKey -1</CODE> can die with a fatal error. This
- will hopefully not be common.</P>
- <P>If MODE is greater then zero, then ReadKey will use it as a timeout value in
- seconds (fractional seconds are allowed), and won't return <A HREF="../../../lib/Pod/perlfunc.html#item_undef"><CODE>undef</CODE></A> until
- that time expires. (Note, again, that some OS's may not support this timeout
- behaviour.) If MODE is less then zero, then this is treated as a timeout
- of zero, and thus will return immediately if no character is waiting. A MODE
- of zero, however, will act like a normal getc.</P>
- <P>There are currently some limitations with this call under Windows. It may be
- possible that non-blocking reads will fail when reading repeating keys from
- more then one console.</P>
- <P></P>
- <DT><STRONG><A NAME="item_ReadLine_MODE_%5B%2C_Filehandle%5D">ReadLine MODE [, Filehandle]</A></STRONG><BR>
- <DD>
- Takes an integer argument, which can currently be one of the following
- values:
- <PRE>
- 0 Perform a normal read using scalar(<FileHandle>)
- -1 Perform a non-blocked read
- >0 Perform a timed read</PRE>
- <P>If there is nothing waiting in the buffer during a non-blocked read, then
- undef will be returned. Note that if the OS does not provide any known
- mechanism for non-blocking reads, then a <CODE>ReadLine 1</CODE> can die with a fatal
- error. This will hopefully not be common. Note that a non-blocking test is
- only performed for the first character in the line, not the entire line.
- This call will probably <STRONG>not</STRONG> do what you assume, especially with
- ReadMode's higher then 1. For example, pressing Space and then Backspace
- would appear to leave you where you started, but any timeouts would now
- be suspended.</P>
- <P>This call is currently not available under Windows.</P>
- <P></P>
- <DT><STRONG><A NAME="item_GetTerminalSize_%5BFilehandle%5D">GetTerminalSize [Filehandle]</A></STRONG><BR>
- <DD>
- Returns either an empty array if this operation is unsupported, or a four
- element array containing: the width of the terminal in characters, the
- height of the terminal in character, the width in pixels, and the height in
- pixels. (The pixel size will only be valid in some environments.)
- <P>Under Windows, this function must be called with an ``output'' filehandle,
- such as STDOUT, or a handle opened to CONOUT$.</P>
- <P></P>
- <DT><STRONG><A NAME="item_SetTerminalSize_WIDTH%2CHEIGHT%2CXPIX%2CYPIX_%5B%2">SetTerminalSize WIDTH,HEIGHT,XPIX,YPIX [, Filehandle]</A></STRONG><BR>
- <DD>
- Return -1 on failure, 0 otherwise. Note that this terminal size is only for
- <STRONG>informative</STRONG> value, and changing the size via this mechanism will <STRONG>not</STRONG>
- change the size of the screen. For example, XTerm uses a call like this when
- it resizes the screen. If any of the new measurements vary from the old, the
- OS will probably send a SIGWINCH signal to anything reading that tty or pty.
- <P>This call does not work under Windows.</P>
- <P></P>
- <DT><STRONG><A NAME="item_GetSpeeds_%5B%2C_Filehandle%5D">GetSpeeds [, Filehandle]</A></STRONG><BR>
- <DD>
- Returns either an empty array if the operation is unsupported, or a two
- value array containing the terminal in and out speeds, in <STRONG>decimal</STRONG>. E.g,
- an in speed of 9600 baud and an out speed of 4800 baud would be returned as
- (9600,4800). Note that currently the in and out speeds will always be
- identical in some OS's. No speeds are reported under Windows.
- <P></P>
- <DT><STRONG><A NAME="item_GetControlChars_%5B%2C_Filehandle%5D">GetControlChars [, Filehandle]</A></STRONG><BR>
- <DD>
- Returns an array containing key/value pairs suitable for a hash. The pairs
- consist of a key, the name of the control character/signal, and the value
- of that character, as a single character. This call does nothing under Windows.
- <P>Each key will be an entry from the following list:</P>
- <PRE>
- DISCARD
- DSUSPEND
- EOF
- EOL
- EOL2
- ERASE
- ERASEWORD
- INTERRUPT
- KILL
- MIN
- QUIT
- QUOTENEXT
- REPRINT
- START
- STATUS
- STOP
- SUSPEND
- SWITCH
- TIME</PRE>
- <P>Thus, the following will always return the current interrupt character,
- regardless of platform.</P>
- <PRE>
- %keys = GetControlChars;
- $int = $keys{INTERRUPT};</PRE>
- <P></P>
- <DT><STRONG><A NAME="item_SetControlChars_%5B%2C_Filehandle%5D">SetControlChars [, Filehandle]</A></STRONG><BR>
- <DD>
- Takes an array containing key/value pairs, as a hash will produce. The pairs
- should consist of a key that is the name of a legal control
- character/signal, and the value should be either a single character, or a
- number in the range 0-255. SetControlChars will die with a runtime error if
- an invalid character name is passed or there is an error changing the
- settings. The list of valid names is easily available via
- <PRE>
- %cchars = GetControlChars();
- @cnames = keys %cchars;</PRE>
- <P>This call does nothing under Windows.</P>
- <P></P></DL>
- <P>
- <HR>
- <H1><A NAME="author">AUTHOR</A></H1>
- <P>Kenneth Albanowski <<A HREF="mailto:kjahds@kjahds.com">kjahds@kjahds.com</A>></P>
- <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
- <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
- <STRONG><P CLASS=block> Term::ReadKey - A perl module for simple terminal control</P></STRONG>
- </TD></TR>
- </TABLE>
-
- </BODY>
-
- </HTML>
-