Keyboard input/Flush the keyboard buffer: Difference between revisions

Added Wren
No edit summary
(Added Wren)
Line 1,451:
=={{header|Vedit macro language}}==
<lang vedit>Key_Purge()</lang>
 
=={{header|Wren}}==
There is currently no direct way to flush the keyboard buffer from Wren-cli.
 
However, the ''System.readByte()'' method reads and removes the next byte from the buffer, blocking the fiber until ''enter'' is pressed. Consequently, the following code will only flush the buffer if ''enter'' is the last key pressed.
 
It is necessary to type in some keys first (and have them echoed) to demonstrate that it is in fact working. 'Raw' mode can't be used here as keyboard input is not buffered in that mode.
<lang ecmascript>import "io" for Stdin
 
System.print("Press some keys followed by enter.")
while (true) {
var b = Stdin.readByte() // reads and removes a key from the buffer
System.print("Removed key with code %(b).")
if (b == 10) break // buffer will be empty when enter key pressed
}
System.print("Keyboard buffer is now empty.")</lang>
 
{{out}}
Sample session when the keys a, b, c, d followed by enter are pressed:
<pre>
Press some keys followed by enter.
abcd
Removed key with code 97.
Removed key with code 98.
Removed key with code 99.
Removed key with code 100.
Removed key with code 10.
Keyboard buffer is now empty.
</pre>
 
=={{header|XPL0}}==
9,490

edits