How do I flush the keyboard buffer in C# using Windows Forms?
I have a barcode scanner which acts like a keyboard. If a really long barcode is scanned and the cancel
@Chris:
Console.KeyAvailable
threw an exception on me because the Console did not have focus.
The exception message was helpful, though. It suggested using Console.In.Peek()
to read in that instance.
I thought it would be worth noting here as an alternate solution and for posterity.
if (-1 < Console.In.Peek()) {
Console.In.ReadToEnd();
}