console.html
来自「perl教程」· HTML 代码 · 共 1,003 行 · 第 1/3 页
HTML
1,003 行
<li>
<p>right column (X of the final point) of the current console window.</p>
</li>
<li>
<p>bottom row (Y of the final point) of the current console window.</p>
</li>
<li>
<p>maximum number of columns for the console window, given the current
buffer size, font and the screen size.</p>
</li>
<li>
<p>maximum number of rows for the console window, given the current
buffer size, font and the screen size.</p>
</li>
</ul>
<p>See also: <code>Attr</code>, <code>Cursor</code>, <code>Size</code>, <code>Window</code>, <a href="#item_maxwindow"><code>MaxWindow</code></a>.</p>
<p>Example:</p>
<pre>
<span class="variable">@info</span> <span class="operator">=</span> <span class="variable">$CONSOLE</span><span class="operator">-></span><span class="variable">Info</span><span class="operator">();</span>
<span class="keyword">print</span> <span class="string">"Cursor at $info[3], $info[4].\n"</span><span class="operator">;</span>
</pre>
<dt><strong><a name="item_input">Input</a></strong>
<dd>
<p>Reads an event from the input buffer. Returns a list of values, which
depending on the event's nature are:</p>
</dd>
<dl>
<dt><strong><a name="item_keyboard_event">keyboard event</a></strong>
<dd>
<p>The list will contain:</p>
</dd>
<ul>
<li>
<p>event type: 1 for keyboard</p>
</li>
<li>
<p>key down: TRUE if the key is being pressed, FALSE if the key is being released</p>
</li>
<li>
<p>repeat count: the number of times the key is being held down</p>
</li>
<li>
<p>virtual keycode: the virtual key code of the key</p>
</li>
<li>
<p>virtual scancode: the virtual scan code of the key</p>
</li>
<li>
<p>char: the ASCII code of the character (if the key is a character key, 0 otherwise)</p>
</li>
<li>
<p>control key state: the state of the control keys (SHIFTs, CTRLs, ALTs, etc.)</p>
</li>
</ul>
<dt><strong><a name="item_mouse_event">mouse event</a></strong>
<dd>
<p>The list will contain:</p>
</dd>
<ul>
<li>
<p>event type: 2 for mouse</p>
</li>
<li>
<p>mouse pos. X: X coordinate (column) of the mouse location</p>
</li>
<li>
<p>mouse pos. Y: Y coordinate (row) of the mouse location</p>
</li>
<li>
<p>button state: the mouse <code>button(s)</code> which are pressed</p>
</li>
<li>
<p>control key state: the state of the control keys (SHIFTs, CTRLs, ALTs, etc.)</p>
</li>
<li>
<p>event flags: the type of the mouse event</p>
</li>
</ul>
</dl>
<p>This method will return <a href="../../lib/Pod/perlfunc.html#item_undef"><code>undef</code></a> on errors. Note that the events
returned are depending on the input <code>Mode</code> of the console; for example,
mouse events are not intercepted unless ENABLE_MOUSE_INPUT is
specified. See also: <a href="#item_getevents"><code>GetEvents</code></a>, <code>InputChar</code>, <code>Mode</code>,
<a href="#item_peekinput"><code>PeekInput</code></a>, <a href="#item_writeinput"><code>WriteInput</code></a>.</p>
<p>Example:</p>
<pre>
<span class="variable">@event</span> <span class="operator">=</span> <span class="variable">$CONSOLE</span><span class="operator">-></span><span class="variable">Input</span><span class="operator">();</span>
</pre>
<dt><strong><a name="item_inputchar_number">InputChar number</a></strong>
<dd>
<p>Reads and returns <em>number</em> characters from the console input buffer,
or <a href="../../lib/Pod/perlfunc.html#item_undef"><code>undef</code></a> on errors. See also: <a href="#item_input"><code>Input</code></a>, <code>Mode</code>.</p>
</dd>
<dd>
<p>Example:</p>
</dd>
<dd>
<pre>
<span class="variable">$key</span> <span class="operator">=</span> <span class="variable">$CONSOLE</span><span class="operator">-></span><span class="variable">InputChar</span><span class="operator">(</span><span class="number">1</span><span class="operator">);</span>
</pre>
</dd>
</li>
<dt><strong><a name="item_inputcp__5bcodepage_5d">InputCP [codepage]</a></strong>
<dd>
<p>Gets or sets the input code page used by the console. Note that this
doesn't apply to a console object, but to the standard input
console. This attribute is used by the Write method. See also:
<code>OutputCP</code>.</p>
</dd>
<dd>
<p>Example:</p>
</dd>
<dd>
<pre>
<span class="variable">$codepage</span> <span class="operator">=</span> <span class="variable">$CONSOLE</span><span class="operator">-></span><span class="variable">InputCP</span><span class="operator">();</span>
<span class="variable">$CONSOLE</span><span class="operator">-></span><span class="variable">InputCP</span><span class="operator">(</span><span class="number">437</span><span class="operator">);</span>
</pre>
</dd>
<dd>
<pre>
<span class="comment"># you may want to use the non-instanciated form to avoid confuzion :)</span>
<span class="variable">$codepage</span> <span class="operator">=</span> <span class="variable">Win32::Console::InputCP</span><span class="operator">();</span>
<span class="variable">Win32::Console::InputCP</span><span class="operator">(</span><span class="number">437</span><span class="operator">);</span>
</pre>
</dd>
</li>
<dt><strong><a name="item_maxwindow">MaxWindow</a></strong>
<dd>
<p>Returns the size of the largest possible console window, based on the
current font and the size of the display. The result is <a href="../../lib/Pod/perlfunc.html#item_undef"><code>undef</code></a> on
errors, otherwise a 2-element list containing col, row.</p>
</dd>
<dd>
<p>Example:</p>
</dd>
<dd>
<pre>
<span class="operator">(</span><span class="variable">$maxCol</span><span class="operator">,</span> <span class="variable">$maxRow</span><span class="operator">)</span> <span class="operator">=</span> <span class="variable">$CONSOLE</span><span class="operator">-></span><span class="variable">MaxWindow</span><span class="operator">();</span>
</pre>
</dd>
</li>
<dt><strong><a name="item_mode__5bflags_5d">Mode [flags]</a></strong>
<dd>
<p>Gets or sets the input or output mode of a console. <em>flags</em> can be a
combination of the following constants:</p>
</dd>
<dd>
<pre>
ENABLE_LINE_INPUT
ENABLE_ECHO_INPUT
ENABLE_PROCESSED_INPUT
ENABLE_WINDOW_INPUT
ENABLE_MOUSE_INPUT
ENABLE_PROCESSED_OUTPUT
ENABLE_WRAP_AT_EOL_OUTPUT</pre>
</dd>
<dd>
<p>For more informations on the meaning of those flags, please refer to
the <a href="#microsoft_s_documentation">Microsoft's Documentation</a>.</p>
</dd>
<dd>
<p>Example:</p>
</dd>
<dd>
<pre>
<span class="variable">$mode</span> <span class="operator">=</span> <span class="variable">$CONSOLE</span><span class="operator">-></span><span class="variable">Mode</span><span class="operator">();</span>
<span class="variable">$CONSOLE</span><span class="operator">-></span><span class="variable">Mode</span><span class="operator">(</span><span class="variable">ENABLE_MOUSE_INPUT</span> <span class="operator">|</span> <span class="variable">ENABLE_PROCESSED_INPUT</span><span class="operator">);</span>
</pre>
</dd>
</li>
<dt><strong><a name="item_mousebuttons">MouseButtons</a></strong>
<dd>
<p>Returns the number of the buttons on your mouse, or <a href="../../lib/Pod/perlfunc.html#item_undef"><code>undef</code></a> on errors.</p>
</dd>
<dd>
<p>Example:</p>
</dd>
<dd>
<pre>
<span class="keyword">print</span> <span class="string">"Your mouse has "</span><span class="operator">,</span> <span class="variable">$CONSOLE</span><span class="operator">-></span><span class="variable">MouseButtons</span><span class="operator">(),</span> <span class="string">" buttons.\n"</span><span class="operator">;</span>
</pre>
</dd>
</li>
<dt><strong><a name="item_new_win32_3a_3aconsole_standard_handle">new Win32::Console standard_handle</a></strong>
<dt><strong><a name="item_new_win32_3a_3aconsole__5baccessmode_2c_sharemode_">new Win32::Console [accessmode, sharemode]</a></strong>
<dd>
<p>Creates a new console object. The first form creates a handle to a
standard channel, <em>standard_handle</em> can be one of the following:</p>
</dd>
<dd>
<pre>
STD_OUTPUT_HANDLE
STD_ERROR_HANDLE
STD_INPUT_HANDLE</pre>
</dd>
<dd>
<p>The second form, instead, creates a console screen buffer in memory,
which you can access for reading and writing as a normal console, and
then redirect on the standard output (the screen) with <a href="#item_display"><code>Display</code></a>. In
this case, you can specify one or both of the following values for
<em>accessmode</em>:</p>
</dd>
<dd>
<pre>
GENERIC_READ
GENERIC_WRITE</pre>
</dd>
<dd>
<p>which are the permissions you will have on the created buffer, and one
or both of the following values for <em>sharemode</em>:</p>
</dd>
<dd>
<pre>
FILE_SHARE_READ
FILE_SHARE_WRITE</pre>
</dd>
<dd>
<p>which affect the way the console can be shared. If you don't specify
any of those parameters, all 4 flags will be used.</p>
</dd>
<dd>
<p>Example:</p>
</dd>
<dd>
<pre>
<span class="variable">$STDOUT</span> <span class="operator">=</span> <span class="variable">new</span> <span class="variable">Win32::Console</span><span class="operator">(</span><span class="variable">STD_OUTPUT_HANDLE</span><span class="operator">);</span>
<span class="variable">$STDERR</span> <span class="operator">=</span> <span class="variable">new</span> <span class="variable">Win32::Console</span><span class="operator">(</span><span class="variable">STD_ERROR_HANDLE</span><span class="operator">);</span>
<span class="variable">$STDIN</span> <span class="operator">=</span> <span class="variable">new</span> <span class="variable">Win32::Console</span><span class="operator">(</span><span class="variable">STD_INPUT_HANDLE</span><span class="operator">);</span>
</pre>
</dd>
<dd>
<pre>
<span class="variable">$BUFFER</span> <span class="operator">=</span> <span class="variable">new</span> <span class="variable">Win32::Console</span><span class="operator">();</span>
<span class="variable">$BUFFER</span> <span class="operator">=</span> <span class="variable">new</span> <span class="variable">Win32::Console</span><span class="operator">(</span><span class="variable">GENERIC_READ</span> <span class="operator">|</span> <span class="variable">GENERIC_WRITE</span><span class="operator">);</span>
</pre>
</dd>
</li>
<dt><strong><a name="item_outputcp__5bcodepage_5d">OutputCP [codepage]</a></strong>
<dd>
<p>Gets or sets the output code page used by the console. Note that this
doesn't apply to a console object, but to the standard output console.
See also: <code>InputCP</code>.</p>
</dd>
<dd>
<p>Example:</p>
</dd>
<dd>
<pre>
<span class="variable">$codepage</span> <span class="operator">=</span> <span class="variable">$CONSOLE</span><span class="operator">-></span><span class="variable">OutputCP</span><span class="operator">();</span>
<span class="variable">$CONSOLE</span><span class="operator">-></span><span class="variable">OutputCP</span><span class="operator">(</span><span class="number">437</span><span class="operator">);</span>
</pre>
</dd>
<dd>
<pre>
<span class="comment"># you may want to use the non-instanciated form to avoid confuzion :)</span>
<span class="variable">$codepage</span> <span class="operator">=</span> <span class="variable">Win32::Console::OutputCP</span><span class="operator">();</span>
<span class="variable">Win32::Console::OutputCP</span><span class="operator">(</span><span class="number">437</span><span class="operator">);</span>
</pre>
</dd>
</li>
<dt><strong><a name="item_peekinput">PeekInput</a></strong>
<dd>
<p>Does exactly the same as <a href="#item_input"><code>Input</code></a>, except that the event read is not
removed from the input buffer. See also: <a href="#item_getevents"><code>GetEvents</code></a>, <a href="#item_input"><code>Input</code></a>,
<code>InputChar</code>, <code>Mode</code>, <a href="#item_writeinput"><code>WriteInput</code></a>.</p>
</dd>
<dd>
<p>Example:</p>
</dd>
<dd>
<pre>
<span class="variable">@event</span> <span class="operator">=</span> <span class="variable">$CONSOLE</span><span class="operator">-></span><span class="variable">PeekInput</span><span class="operator">();</span>
</pre>
</dd>
</li>
<dt><strong><a name="item_readattr__5bnumber_2c_col_2c_row_5d">ReadAttr [number, col, row]</a></strong>
<dd>
<p>Reads the specified <em>number</em> of consecutive attributes, beginning at
<em>col</em>, <em>row</em>, from the console. Returns the attributes read (a
variable containing one character for each attribute), or <a href="../../lib/Pod/perlfunc.html#item_undef"><code>undef</code></a> on
errors. You can then pass the returned variable to <code>WriteAttr</code> to
restore the saved attributes on screen. See also: <code>ReadChar</code>,
<code>ReadRect</code>.</p>
</dd>
<dd>
<p>Example:</p>
</dd>
<dd>
<pre>
<span class="variable">$colors</span> <span class="operator">=</span> <span class="variable">$CONSOLE</span><span class="operator">-></span><span class="variable">ReadAttr</span><span class="operator">(</span><span class="number">80</span><span class="operator">*</span><span class="number">25</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">);</span>
</pre>
</dd>
</li>
<dt><strong><a name="item_readchar__5bnumber_2c_col_2c_row_5d">ReadChar [number, col, row]</a></strong>
<dd>
<p>Reads the specified <em>number</em> of consecutive characters, beginning at
<em>col</em>, <em>row</em>, from the console. Returns a string containing the
characters read, or <a href="../../lib/Pod/perlfunc.html#item_undef"><code>undef</code></a> on errors. You can then pass the
returned variable to <code>WriteChar</code> to restore the saved characters on
screen. See also: <code>ReadAttr</code>, <code>ReadRect</code>.</p>
</dd>
<dd>
<p>Example:</p>
</dd>
<dd>
<pre>
<span class="variable">$chars</span> <span class="operator">=</span> <span class="variable">$CONSOLE</span><span class="operator">-></span><span class="variable">ReadChar</span><span class="operator">(</span><span class="number">80</span><span class="operator">*</span><span class="number">25</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">);</span>
</pre>
</dd>
</li>
<dt><strong><a name="item_readrect_left_2c_top_2c_right_2c_bottom">ReadRect left, top, right, bottom</a></strong>
<dd>
<p>Reads the content (characters and attributes) of the rectangle
specified by <em>left</em>, <em>top</em>, <em>right</em>, <em>bottom</em> from the console.
Returns a string containing the rectangle read, or <a href="../../lib/Pod/perlfunc.html#item_undef"><code>undef</code></a> on errors.
You can then pass the returned variable to <code>WriteRect</code> to restore the
saved rectangle on screen (or on another console). See also:
<code>ReadAttr</code>, <code>ReadChar</code>.</p>
</dd>
<dd>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?