Keyboard input/Flush the keyboard buffer: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
(Added Commodore BASIC)
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 39:
Put_Line (Get_Line);
end Flushtest;</lang>
 
=={{header|AWK}}==
<lang AWK>
Line 229 ⟶ 230:
_STD_conio();
}</lang>
 
=={{header|DCL}}==
<lang>$ wait 0::10 ! gives us 10 seconds to get keystrokes into the type-ahead buffer
Line 255 ⟶ 257:
<lang Euphoria>while get_key()!=-1 do
end while</lang>
 
=={{header|FreeBASIC}}==
<lang freebasic>' FB 1.05.0 Win64
 
' Get characters from the keyboard buffer until there are none left
While Inkey <> "" : Wend
Print "Keyboard buffer flushed"
Sleep</lang>
 
=={{header|Go}}==
Line 309 ⟶ 319:
}
</lang>
 
=={{header|FreeBASIC}}==
<lang freebasic>' FB 1.05.0 Win64
 
' Get characters from the keyboard buffer until there are none left
While Inkey <> "" : Wend
Print "Keyboard buffer flushed"
Sleep</lang>
 
=={{header|Haskell}}==
Line 369 ⟶ 371:
end
</lang>
 
 
=={{header|Kotlin}}==
Line 465 ⟶ 466:
# Don't forget to restore the readmode, when we are finished using the keyboard
ReadMode 'restore';</lang>
 
=={{header|Perl 6}}==
{{works with|Rakudo|2018.12}}
Using termios to set some input attributes, flush the buffer & do unbuffered reads. Longer than strictly necessary to demonstrate concepts and make it easy to verify that it actually works as advertised.
<lang perl6>use Term::termios;
 
constant $saved = Term::termios.new( :fd($*IN.native-descriptor) ).getattr;
constant $termios = Term::termios.new( :fd($*IN.native-descriptor) ).getattr;
 
# set some modified input flags
$termios.unset_iflags(<BRKINT ICRNL ISTRIP IXON>);
$termios.unset_lflags(< ECHO ICANON IEXTEN>);
$termios.setattr(:DRAIN);
 
# reset terminal to original settings on exit
END { $saved.setattr(:NOW) }
 
 
# Sleep for a few seconds to give you time to fill the input buffer,
# type a bunch of random characters.
sleep 2;
 
# ------- The actual task --------
# Flush the input buffer
 
$termios.setattr(:FLUSH);
 
# --------------------------------
 
# Ctrl-C to exit
loop {
# Read up to 5 bytes from STDIN
# F5 through F12 are 5 bytes each
my $keypress = $*IN.read: 5;
# print the ordinals of the keypress character
print $keypress.decode.ords;
print "|";
}</lang>
 
=={{header|Phix}}==
Line 556 ⟶ 519:
(printf "You pressed ~a\n" (read-char)))
</lang>
 
=={{header|Perl 6Raku}}==
(formerly Perl 6)
{{works with|Rakudo|2018.12}}
Using termios to set some input attributes, flush the buffer & do unbuffered reads. Longer than strictly necessary to demonstrate concepts and make it easy to verify that it actually works as advertised.
<lang perl6>use Term::termios;
 
constant $saved = Term::termios.new( :fd($*IN.native-descriptor) ).getattr;
constant $termios = Term::termios.new( :fd($*IN.native-descriptor) ).getattr;
 
# set some modified input flags
$termios.unset_iflags(<BRKINT ICRNL ISTRIP IXON>);
$termios.unset_lflags(< ECHO ICANON IEXTEN>);
$termios.setattr(:DRAIN);
 
# reset terminal to original settings on exit
END { $saved.setattr(:NOW) }
 
 
# Sleep for a few seconds to give you time to fill the input buffer,
# type a bunch of random characters.
sleep 2;
 
# ------- The actual task --------
# Flush the input buffer
 
$termios.setattr(:FLUSH);
 
# --------------------------------
 
# Ctrl-C to exit
loop {
# Read up to 5 bytes from STDIN
# F5 through F12 are 5 bytes each
my $keypress = $*IN.read: 5;
# print the ordinals of the keypress character
print $keypress.decode.ords;
print "|";
}</lang>
 
=={{header|REXX}}==
Line 662 ⟶ 664:
=={{header|Scala}}==
<lang scala>def flush() { out.flush() }</lang>
 
=={{header|Seed7}}==
The Seed7 library [http://seed7.sourceforge.net/libraries/keybd.htm keybd.s7i]
10,333

edits