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

📄 readkey.pm

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 PM
📖 第 1 页 / 共 2 页
字号:
##  $Id: ReadKey.pm,v 2.23 2005/01/11 21:16:31 jonathan Exp $#=head1 NAMETerm::ReadKey - A perl module for simple terminal control=head1 SYNOPSIS	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=head1 DESCRIPTIONTerm::ReadKey is a compiled perl module dedicated to providing simplecontrol over terminal driver modes (cbreak, raw, cooked, etc.,) support fornon-blocking reads, if the architecture allows, and some generalized handyfunctions for working with terminals. One of the main goals is to have thefunctions as portable as possible, so you can just plug in "useTerm::ReadKey" on any architecture and have a good likelyhood of it working.=over 8=item ReadMode MODE [, Filehandle]Takes an integer argument, which can currently be one of the following values:    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)               Or, you may use the synonyms:        restore    normal    noecho    cbreak    raw    ultra-rawThese functions are automatically applied to the STDIN handle if noother handle is supplied. Modes 0 and 5 have some special propertiesworth mentioning: not only will mode 0 restore original settings, but itcause the next ReadMode call to save a new set of default settings. Mode5 is similar to mode 4, except no CR/LF translation is performed, and ifpossible, parity will be disabled (only if not being used by the terminal,however. It is no different from mode 4 under Windows.)If you are executing another program that may be changing the terminal mode,you will either want to say    ReadMode 1    system('someprogram');    ReadMode 1;    which resets the settings after the program has run, or:    $somemode=1;    ReadMode 0;    system('someprogram');    ReadMode 1;    which records any changes the program may have made, before resetting themode.=item ReadKey MODE [, Filehandle]Takes an integer argument, which can currently be one of the following values:    0    Perform a normal read using getc    -1   Perform a non-blocked read    >0	 Perform a timed read(If the filehandle is not supplied, it will default to STDIN.) If there isnothing waiting in the buffer during a non-blocked read, then undef will bereturned. Note that if the OS does not provide any known mechanism fornon-blocking reads, then a C<ReadKey -1> can die with a fatal error. Thiswill hopefully not be common.If MODE is greater then zero, then ReadKey will use it as a timeout value inseconds (fractional seconds are allowed), and won't return C<undef> untilthat time expires. (Note, again, that some OS's may not support this timeoutbehaviour.) If MODE is less then zero, then this is treated as a timeoutof zero, and thus will return immediately if no character is waiting. A MODEof zero, however, will act like a normal getc.There are currently some limitations with this call under Windows. It may bepossible that non-blocking reads will fail when reading repeating keys frommore then one console.=item ReadLine MODE [, Filehandle]Takes an integer argument, which can currently be one of the following values:    0    Perform a normal read using scalar(<FileHandle>)    -1   Perform a non-blocked read    >0	 Perform a timed readIf there is nothing waiting in the buffer during a non-blocked read, thenundef will be returned. Note that if the OS does not provide any knownmechanism for non-blocking reads, then a C<ReadLine 1> can die with a fatalerror. This will hopefully not be common. Note that a non-blocking test isonly performed for the first character in the line, not the entire line.This call will probably B<not> do what you assume, especially withReadMode's higher then 1. For example, pressing Space and then Backspacewould appear to leave you where you started, but any timeouts would nowbe suspended.This call is currently not available under Windows.=item GetTerminalSize [Filehandle]Returns either an empty array if this operation is unsupported, or a fourelement array containing: the width of the terminal in characters, theheight of the terminal in character, the width in pixels, and the height inpixels. (The pixel size will only be valid in some environments.)Under Windows, this function must be called with an "output" filehandle,such as STDOUT, or a handle opened to CONOUT$.=item SetTerminalSize WIDTH,HEIGHT,XPIX,YPIX [, Filehandle]Return -1 on failure, 0 otherwise. Note that this terminal size is only forB<informative> value, and changing the size via this mechanism will B<not>change the size of the screen. For example, XTerm uses a call like this whenit resizes the screen. If any of the new measurements vary from the old, theOS will probably send a SIGWINCH signal to anything reading that tty or pty.This call does not work under Windows.=item GetSpeeds [, Filehandle]Returns either an empty array if the operation is unsupported, or a twovalue array containing the terminal in and out speeds, in B<decimal>. 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 beidentical in some OS's. No speeds are reported under Windows.=item GetControlChars [, Filehandle]Returns an array containing key/value pairs suitable for a hash. The pairsconsist of a key, the name of the control character/signal, and the valueof that character, as a single character. This call does nothing under Windows.Each key will be an entry from the following list:	DISCARD	DSUSPEND	EOF	EOL	EOL2	ERASE	ERASEWORD	INTERRUPT	KILL	MIN	QUIT	QUOTENEXT	REPRINT	START	STATUS	STOP	SUSPEND	SWITCH	TIMEThus, the following will always return the current interrupt character,regardless of platform.	%keys = GetControlChars;	$int = $keys{INTERRUPT};=item SetControlChars [, Filehandle]Takes an array containing key/value pairs, as a hash will produce. The pairsshould consist of a key that is the name of a legal controlcharacter/signal, and the value should be either a single character, or anumber in the range 0-255. SetControlChars will die with a runtime error ifan invalid character name is passed or there is an error changing thesettings. The list of valid names is easily available via	%cchars = GetControlChars();	@cnames = keys %cchars;This call does nothing under Windows.=back=head1 AUTHORKenneth Albanowski <kjahds@kjahds.com>Currently maintained by Jonathan Stowe <jns@gellyfish.com>=cutpackage Term::ReadKey;$VERSION = '2.30';require Exporter;require AutoLoader;require DynaLoader;use Carp;@ISA = qw(Exporter AutoLoader DynaLoader);# Items to export into callers namespace by default# (move infrequently used names to @EXPORT_OK below)@EXPORT = qw(  ReadKey  ReadMode  ReadLine  GetTerminalSize  SetTerminalSize  GetSpeed  GetControlChars  SetControlChars);@EXPORT_OK = qw();bootstrap Term::ReadKey;# Preloaded methods go here.  Autoload methods go after __END__, and are# processed by the autosplit program.# Should we use LINES and COLUMNS to try and get the terminal size?# Change this to zero if you have systems where these are commonly# set to erroneous values. (But if either are nero zero, they won't be# used anyhow.)$UseEnv = 1;%modes = (    original    => 0,    restore     => 0,    normal      => 1,    noecho      => 2,    cbreak      => 3,    raw         => 4,    'ultra-raw' => 5);sub ReadMode{    my ($mode) = $modes{ $_[0] };    my ($fh) = normalizehandle( ( @_ > 1 ? $_[1] : \*STDIN ) );    if ( defined($mode) ) { SetReadMode( $mode, $fh ) }    elsif ( $_[0] =~ /^\d/ ) { SetReadMode( $_[0], $fh ) }    else { croak("Unknown terminal mode `$_[0]'"); }}sub normalizehandle{    my ($file) = @_;    #	print "Handle = $file\n";    if ( ref($file) ) { return $file; }    # Reference is fine    #	if($file =~ /^\*/) { return $file; } # Type glob is good    if ( ref( \$file ) eq 'GLOB' ) { return $file; }    # Glob is good    #	print "Caller = ",(caller(1))[0],"\n";    return \*{ ( ( caller(1) )[0] ) . "::$file" };}sub GetTerminalSize

⌨️ 快捷键说明

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