|
95 | 95 | <div class="headertitle"><div class="title">INKEY$ Function </div></div> |
96 | 96 | </div><!--header--> |
97 | 97 | <div class="contents"> |
98 | | -<div class="textblock"><div class="fragment"><div class="line">A$= INKEY$</div> |
99 | | -</div><!-- fragment --><p>Returns the <b>key that has been pressed</b> as a string. If no key has been pressed since the last call, it returns an <b>empty string</b>.</p> |
100 | | -<p><span class="tt">INKEY$</span> consumes input from the <b>keyboard buffer</b>. If multiple keys have been pressed between this call and the last call to <span class="tt">INKEY$</span> (or an <span class="tt">INPUT</span> statement), it will take multiple calls to retrieve them all.</p> |
| 98 | +<div class="textblock"><div class="fragment"><div class="line">A$= INKEY$(STRING)</div> |
| 99 | +</div><!-- fragment --><p>INKEY$ checks for key state on the keyboard. It has two modes of operation:</p> |
| 100 | +<ul> |
| 101 | +<li>If the string parameter passed is an empty string, it will check if any key is waiting in the keyboard buffer, consuming it from the buffer and returning it, or returning an empty string if no key is available.</li> |
| 102 | +<li>If the string parameter passed in is a non-empty single-character string, it will check if that key is currently held, and will not consume it from the buffer. Because this form of the function is not consuming from the buffer you may use this form to concurrently check for multiple depressed keys at the same time. Note that you must still drain the buffer. Use a separate INKEY$("") call to drain any pending key presses so the buffer does not fill. <b>US-ASCII values (A-Z) are considered case-insensitive</b> in the parameter when using this form of <span class="tt">INKEY$</span>.</li> |
| 103 | +<li>When <span class="tt">INKEY$</span> consumes input from the <b>keyboard buffer</b> by using an empty parameter, if multiple keys have been pressed between this call and the last call to <span class="tt">INKEY$</span> (or an <span class="tt">INPUT</span> statement), it will take multiple calls to retrieve them all.</li> |
| 104 | +</ul> |
101 | 105 | <hr /> |
102 | 106 | <h3 class="doxsection"><a class="anchor" id="extended-keys"></a> |
103 | 107 | Extended keys</h3> |
104 | 108 | <p>Some non-printing keys return special character codes rather than ASCII. These values can be retrieved by wrapping <span class="tt">INKEY$</span> with <span class="tt">ASC()</span>.</p> |
105 | 109 | <table class="markdownTable"> |
106 | 110 | <tr class="markdownTableHead"> |
107 | | -<th class="markdownTableHeadNone">Key </th><th class="markdownTableHeadNone"><span class="tt">ASC(INKEY$)</span> value </th></tr> |
| 111 | +<th class="markdownTableHeadNone">Key </th><th class="markdownTableHeadNone"><span class="tt">ASC(INKEY$(""))</span> value </th></tr> |
108 | 112 | <tr class="markdownTableRowOdd"> |
109 | 113 | <td class="markdownTableBodyNone">PAGEUP </td><td class="markdownTableBodyNone">245 </td></tr> |
110 | 114 | <tr class="markdownTableRowEven"> |
@@ -132,23 +136,29 @@ <h3 class="doxsection"><a class="anchor" id="examples-100"></a> |
132 | 136 | <div class="fragment"><div class="line">REM Wait for a keypress</div> |
133 | 137 | <div class="line">PRINT "Press a key..."</div> |
134 | 138 | <div class="line">REPEAT</div> |
135 | | -<div class="line"> k$ = INKEY$</div> |
| 139 | +<div class="line"> k$ = INKEY$("")</div> |
136 | 140 | <div class="line">UNTIL k$ > ""</div> |
137 | 141 | <div class="line">PRINT "You pressed: "; k$</div> |
138 | 142 | </div><!-- fragment --><div class="fragment"><div class="line">REM Handle arrow keys</div> |
139 | | -<div class="line">k$ = INKEY$</div> |
| 143 | +<div class="line">k$ = INKEY$("")</div> |
140 | 144 | <div class="line">IF k$ > "" THEN</div> |
141 | 145 | <div class="line"> code = ASC(k$)</div> |
142 | 146 | <div class="line"> IF code = 250 THEN PRINT "Up arrow pressed"</div> |
143 | 147 | <div class="line"> IF code = 251 THEN PRINT "Down arrow pressed"</div> |
144 | 148 | <div class="line">ENDIF</div> |
| 149 | +</div><!-- fragment --><div class="fragment"><div class="line">REM multiple key example</div> |
| 150 | +<div class="line">PRINT "Press both A and Z together to exit"</div> |
| 151 | +<div class="line">REPEAT</div> |
| 152 | +<div class="line">UNTIL INKEY$("A") <> "" AND INKEY$("Z") <> ""</div> |
| 153 | +<div class="line">END</div> |
145 | 154 | </div><!-- fragment --><hr /> |
146 | 155 | <h3 class="doxsection"><a class="anchor" id="notes-99"></a> |
147 | 156 | Notes</h3> |
148 | 157 | <ul> |
149 | 158 | <li>Printable characters return their usual ASCII values (e.g. <span class="tt">"A"</span> → 65).</li> |
150 | 159 | <li>Extended keys must be checked via <span class="tt">ASC()</span>.</li> |
151 | | -<li>If no key is pressed, result is <span class="tt">""</span> (empty string).</li> |
| 160 | +<li>If no key is pressed, the result is <span class="tt">""</span> (empty string).</li> |
| 161 | +<li>If the parameter to <span class="tt">INKEY$</span> contains more than one character, any characters except the first are ignored.</li> |
152 | 162 | </ul> |
153 | 163 | <hr /> |
154 | 164 | <p><b>See also:</b> <a class="el" href="ASC.html">ASC</a> · <a class="el" href="INPUT.html">INPUT</a> </p> |
|
0 commit comments