📄 term::readkey.3
字号:
.\" Automatically generated by Pod::Man 2.16 (Pod::Simple 3.05).\".\" Standard preamble:.\" ========================================================================.de Sh \" Subsection heading.br.if t .Sp.ne 5.PP\fB\\$1\fR.PP...de Sp \" Vertical space (when we can't use .PP).if t .sp .5v.if n .sp...de Vb \" Begin verbatim text.ft CW.nf.ne \\$1...de Ve \" End verbatim text.ft R.fi...\" Set up some character translations and predefined strings. \*(-- will.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left.\" double quote, and \*(R" will give a right double quote. \*(C+ will.\" give a nicer C++. Capital omega is used to do unbreakable dashes and.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,.\" nothing in troff, for use with C<>..tr \(*W-.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'.ie n \{\. ds -- \(*W-. ds PI pi. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch. ds L" "". ds R" "". ds C` "". ds C' ""'br\}.el\{\. ds -- \|\(em\|. ds PI \(*p. ds L" ``. ds R" '''br\}.\".\" Escape single quotes in literal strings from groff's Unicode transform..ie \n(.g .ds Aq \(aq.el .ds Aq '.\".\" If the F register is turned on, we'll generate index entries on stderr for.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index.\" entries marked with X<> in POD. Of course, you'll have to process the.\" output yourself in some meaningful fashion..ie \nF \{\. de IX. tm Index:\\$1\t\\n%\t"\\$2"... nr % 0. rr F.\}.el \{\. de IX...\}.\".\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2)..\" Fear. Run. Save yourself. No user-serviceable parts.. \" fudge factors for nroff and troff.if n \{\. ds #H 0. ds #V .8m. ds #F .3m. ds #[ \f1. ds #] \fP.\}.if t \{\. ds #H ((1u-(\\\\n(.fu%2u))*.13m). ds #V .6m. ds #F 0. ds #[ \&. ds #] \&.\}. \" simple accents for nroff and troff.if n \{\. ds ' \&. ds ` \&. ds ^ \&. ds , \&. ds ~ ~. ds /.\}.if t \{\. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u". ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'.\}. \" troff and (daisy-wheel) nroff accents.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'.ds 8 \h'\*(#H'\(*b\h'-\*(#H'.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#].ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#].ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#].ds ae a\h'-(\w'a'u*4/10)'e.ds Ae A\h'-(\w'A'u*4/10)'E. \" corrections for vroff.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'. \" for low resolution devices (crt and lpr).if \n(.H>23 .if \n(.V>19 \\{\. ds : e. ds 8 ss. ds o a. ds d- d\h'-1'\(ga. ds D- D\h'-1'\(hy. ds th \o'bp'. ds Th \o'LP'. ds ae ae. ds Ae AE.\}.rm #[ #] #H #V #F C.\" ========================================================================.\".IX Title "ReadKey 3".TH ReadKey 3 "2005-01-11" "perl v5.10.0" "User Contributed Perl Documentation".\" For nroff, turn off justification. Always turn off hyphenation; it makes.\" way too many mistakes in technical documents..if n .ad l.nh.SH "NAME"Term::ReadKey \- A perl module for simple terminal control.SH "SYNOPSIS".IX Header "SYNOPSIS".Vb 7\& use Term::ReadKey;\& ReadMode 4; # Turn off controls keys\& while (not defined ($key = ReadKey(\-1))) {\& # No key yet\& }\& print "Get key $key\en";\& ReadMode 0; # Reset tty mode before exiting.Ve.SH "DESCRIPTION".IX Header "DESCRIPTION"Term::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 \*(L"useTerm::ReadKey\*(R" on any architecture and have a good likelyhood of it working..IP "ReadMode \s-1MODE\s0 [, Filehandle]" 8.IX Item "ReadMode MODE [, Filehandle]"Takes an integer argument, which can currently be one of the following values:.Sp.Vb 8\& 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\-raw.Ve.SpThese functions are automatically applied to the \s-1STDIN\s0 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 \s-1CR/LF\s0 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.).SpIf you are executing another program that may be changing the terminal mode,you will either want to say.Sp.Vb 3\& ReadMode 1\& system(\*(Aqsomeprogram\*(Aq);\& ReadMode 1;.Ve.Spwhich resets the settings after the program has run, or:.Sp.Vb 4\& $somemode=1;\& ReadMode 0;\& system(\*(Aqsomeprogram\*(Aq);\& ReadMode 1;.Ve.Spwhich records any changes the program may have made, before resetting themode..IP "ReadKey \s-1MODE\s0 [, Filehandle]" 8.IX Item "ReadKey MODE [, Filehandle]"Takes an integer argument, which can currently be one of the following values:.Sp.Vb 3\& 0 Perform a normal read using getc\& \-1 Perform a non\-blocked read\& >0 Perform a timed read.Ve.Sp(If the filehandle is not supplied, it will default to \s-1STDIN\s0.) If there isnothing waiting in the buffer during a non-blocked read, then undef will bereturned. Note that if the \s-1OS\s0 does not provide any known mechanism fornon-blocking reads, then a \f(CW\*(C`ReadKey \-1\*(C'\fR can die with a fatal error. Thiswill hopefully not be common..SpIf \s-1MODE\s0 is greater then zero, then ReadKey will use it as a timeout value inseconds (fractional seconds are allowed), and won't return \f(CW\*(C`undef\*(C'\fR untilthat time expires. (Note, again, that some \s-1OS\s0's may not support this timeoutbehaviour.) If \s-1MODE\s0 is less then zero, then this is treated as a timeoutof zero, and thus will return immediately if no character is waiting. A \s-1MODE\s0of zero, however, will act like a normal getc..SpThere 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..IP "ReadLine \s-1MODE\s0 [, Filehandle]" 8.IX Item "ReadLine MODE [, Filehandle]"Takes an integer argument, which can currently be one of the following values:.Sp.Vb 3\& 0 Perform a normal read using scalar(<FileHandle>)\& \-1 Perform a non\-blocked read\& >0 Perform a timed read.Ve.SpIf there is nothing waiting in the buffer during a non-blocked read, thenundef will be returned. Note that if the \s-1OS\s0 does not provide any knownmechanism for non-blocking reads, then a \f(CW\*(C`ReadLine 1\*(C'\fR 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 \fBnot\fR 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..SpThis call is currently not available under Windows..IP "GetTerminalSize [Filehandle]" 8.IX 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.).SpUnder Windows, this function must be called with an \*(L"output\*(R" filehandle,such as \s-1STDOUT\s0, or a handle opened to \s-1CONOUT$\s0..IP "SetTerminalSize \s-1WIDTH\s0,HEIGHT,XPIX,YPIX [, Filehandle]" 8.IX Item "SetTerminalSize WIDTH,HEIGHT,XPIX,YPIX [, Filehandle]"Return \-1 on failure, 0 otherwise. Note that this terminal size is only for\&\fBinformative\fR value, and changing the size via this mechanism will \fBnot\fRchange 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, the\&\s-1OS\s0 will probably send a \s-1SIGWINCH\s0 signal to anything reading that tty or pty..SpThis call does not work under Windows..IP "GetSpeeds [, Filehandle]" 8.IX 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 \fBdecimal\fR. 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 \s-1OS\s0's. No speeds are reported under Windows..IP "GetControlChars [, Filehandle]" 8.IX 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..SpEach key will be an entry from the following list:.Sp.Vb 10\& DISCARD\& DSUSPEND\& EOF\& EOL\& EOL2\& ERASE\& ERASEWORD\& INTERRUPT\& KILL\& MIN\& QUIT\& QUOTENEXT\& REPRINT\& START\& STATUS\& STOP\& SUSPEND\& SWITCH\& TIME.Ve.SpThus, the following will always return the current interrupt character,regardless of platform..Sp.Vb 2\& %keys = GetControlChars;\& $int = $keys{INTERRUPT};.Ve.IP "SetControlChars [, Filehandle]" 8.IX 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.Sp.Vb 2\& %cchars = GetControlChars();\& @cnames = keys %cchars;.Ve.SpThis call does nothing under Windows..SH "AUTHOR".IX Header "AUTHOR"Kenneth Albanowski <kjahds@kjahds.com>.PPCurrently maintained by Jonathan Stowe <jns@gellyfish.com>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -