📄 ch22_02.htm
字号:
<html><head><title>Win32::Console (Perl in a Nutshell, 2nd Edition)</title><link rel="stylesheet" type="text/css" href="../style/style1.css" /><meta name="DC.Creator" content="Stephen Spainhour" /><meta name="DC.Format" content="text/xml" scheme="MIME" /><meta name="DC.Language" content="en-US" /><meta name="DC.Publisher" content="O'Reilly & Associates, Inc." /><meta name="DC.Source" scheme="ISBN" content="0596002416L" /><meta name="DC.Subject.Keyword" content="stuff" /><meta name="DC.Title" content="Perl in a Nutshell, 2nd Edition" /><meta name="DC.Type" content="Text.Monograph" /></head><body bgcolor="#ffffff"><img src="gifs/smbanner.gif" usemap="#banner-map" border="0" alt="Book Home" /><map name="banner-map"><area shape="rect" coords="1,-2,616,66" href="index.htm" alt="Java and XSLT" /><area shape="rect" coords="629,-11,726,25" href="jobjects/fsearch.htm" alt="Search this book" /></map><div class="navbar"><table width="684" border="0"><tr><td align="left" valign="top" width="228"><a href="ch22_01.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0" /></a></td><td align="center" valign="top" width="228" /><td align="right" valign="top" width="228"><a href="ch22_03.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0" /></a></td></tr></table></div><h2 class="sect1">22.2. Win32::Console</h2><p><a name="INDEX-3173" /><a name="INDEX-3174" />Win32::Console implements theWin32 console and character mode functions. They give you fullcontrol on the console input and output, including support ofoffscreen console buffers (e.g., multiple screen pages); reading andwriting of characters, attributes, and whole portions of the screen;and complete processing of keyboard and mouse events.</p><p><a name="INDEX-3175" />The <tt class="literal">new</tt> constructoris used to create a console object. It can take two forms:</p><blockquote><pre class="code">$con = Win32::Console->new(<em class="replaceable"><tt>standard_handle</tt></em>); $con = Win32::Console->new(<em class="replaceable"><tt>accessmode</em>, <em class="replaceable">sharemode</tt></em>);</pre></blockquote><p>The first form creates a handle to a standard channel.<em class="replaceable"><tt>standard_handle</tt></em> can be one of<tt class="literal">STD_OUTPUT_HANDLE</tt>,<tt class="literal">STD_ERROR_HANDLE</tt>, or<tt class="literal">STD_INPUT_HANDLE</tt>.</p><p>The second form creates a console screen buffer in memory, which youcan access for reading and writing as a normal console, and thenredirect on the standard output (the screen) with<tt class="literal">Display</tt>. In this case, you can specify<em class="replaceable"><tt>accessmode</tt></em> to be<tt class="literal">GENERIC_READ</tt>, <tt class="literal">GENERIC_WRITE</tt>, orboth, determining the permissions you will have on the createdbuffer.</p><p><em class="replaceable"><tt>sharemode</tt></em> affects how the console can beshared. It can be specified as either<tt class="literal">FILE_SHARE_READ</tt>,<tt class="literal">FILE_SHARE_WRITE</tt>, or both. If youdon't specify any of those parameters, all fourflags will be used.</p><p>The following methods are supported by the Win32::Console module.</p><a name="INDEX-3176" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>Alloc</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">cons</em>->Alloc</pre><p><a name="INDEX-3176" />Allocates a new console forthe process. Returns <tt class="literal">undef</tt> on error or a nonzerovalue on success. A process cannot be associated with more than oneconsole, so this method will fail if there is already an allocatedconsole. Use <tt class="literal">Free</tt> to detach the process from theconsole, and then call <tt class="literal">Alloc</tt> to create a newconsole.</p></div><a name="INDEX-3177" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>Attr</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">cons</em>->Attr([<em class="replaceable">attr</em>])</pre><p><a name="INDEX-3177" />Gets or sets the currentconsole attribute. This attribute is used by the<tt class="literal">Write</tt> method.</p></div><a name="INDEX-3178" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>Cls</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">cons</em>->Cls([<em class="replaceable">attr</em>])</pre><p><a name="INDEX-3178" />Clears the console with thespecified <em class="replaceable"><tt>attr</tt></em>, if given. Uses<tt class="literal">ATTR_NORMAL</tt> otherwise.</p></div><a name="INDEX-3179" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>Cursor</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">cons</em>->Cursor([<em class="replaceable">x</em>, <em class="replaceable">y</em>, <em class="replaceable">size</em>, <em class="replaceable">visible</em>])</pre><p><a name="INDEX-3179" />Gets or sets cursor positionand appearance. Returns <tt class="literal">undef</tt> on error, or afour-element list containing <em class="replaceable"><tt>x</tt></em>,<em class="replaceable"><tt>y</em>, <em class="replaceable">size</tt></em>, and<em class="replaceable"><tt>visible</em>. <em class="replaceable">x</tt></em> and<em class="replaceable"><tt>y</tt></em> give the current cursor position.</p></div><a name="INDEX-3180" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>Display</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">cons</em>->Display</pre><p><a name="INDEX-3180" />Displays the specifiedconsole on the screen. Returns <tt class="literal">undef</tt> on error or anonzero value on success.</p></div><a name="INDEX-3181" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>FillAttr</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">cons</em>->FillAttr([<em class="replaceable">value</em>, <em class="replaceable">number</em>, <em class="replaceable">col</em>, <em class="replaceable">row</em>])</pre><p><a name="INDEX-3181" />Fills the specified<em class="replaceable"><tt>number</tt></em> of consecutive attributes,beginning at <em class="replaceable"><tt>col</tt></em>,<em class="replaceable"><tt>row</tt></em>, with the<em class="replaceable"><tt>value</tt></em> specified. Returns the number ofattributes filled, or <tt class="literal">undef</tt> on error.</p></div><a name="INDEX-3182" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>FillChar</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">cons</em>->FillChar(<em class="replaceable">char</em>, <em class="replaceable">number</em>, <em class="replaceable">col</em>, <em class="replaceable">row</em>)</pre><p><a name="INDEX-3182" />Fills the specified<em class="replaceable"><tt>number</tt></em> of consecutive characters,beginning at <em class="replaceable"><tt>col</tt></em>,<em class="replaceable"><tt>row</tt></em>, with the character specified in<em class="replaceable"><tt>char</tt></em>. Returns the number of charactersfilled, or <tt class="literal">undef</tt> on error.</p></div><a name="INDEX-3183" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>Flush</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">cons</em>->Flush</pre><p><a name="INDEX-3183" />Flushes the console input buffer. Allthe events in the buffer are discarded. Returns<tt class="literal">undef</tt> on error, a nonzero value on success.</p></div><a name="INDEX-3184" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>Free</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">cons</em>->Free</pre><p><a name="INDEX-3184" />Detaches the process from theconsole. Returns <tt class="literal">undef</tt> on error, a nonzero valueon success.</p></div><a name="INDEX-3185" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>GenerateCtrlEvent</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">cons</em>->GenerateCtrlEvent([<em class="replaceable">type</em>, <em class="replaceable">processgroup</em>])</pre><p><a name="INDEX-3185" />Sends a break signal of thespecified type to the specified process group.<em class="replaceable"><tt>type</tt></em> can be one of<tt class="literal">CTRL_BREAK_EVENT</tt> or<tt class="literal">CTRL_C_EVENT</tt>, signaling, respectively, thepressing of Ctrl + Break and Ctrl-C. If not specified,<em class="replaceable"><tt>type</tt></em> defaults to<tt class="literal">CTRL_C_EVENT</tt>.<em class="replaceable"><tt>processgroup</tt></em> is the PID of a processsharing the same console. If omitted, it defaults to<tt class="literal">0</tt> (the current process), which is also the onlymeaningful value that you can pass to this function. Returns<tt class="literal">undef</tt> on error, a nonzero value on success.</p></div><a name="INDEX-3186" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>GetEvents</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">cons</em>->GetEvents</pre><p><a name="INDEX-3186" />Returns the number of unreadinput events in the console's input buffer, or<tt class="literal">undef</tt> on error.</p></div><a name="INDEX-3187" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>Info</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">cons</em>->Info</pre><p><a name="INDEX-3187" />Returns an array ofinformation about the console, which contains:</p><ul><li><p>Number of columns (X size) of the console buffer</p></li><li><p>Number of rows (Y size) of the console buffer</p></li><li><p>Current column (X position) of the cursor</p></li><li>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -