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
You could do BIOS level flushing (http://support.microsoft.com/?scid=kb%3Ben-us%3B43993&x=22&y=10) but I would advise against this low level approach since Windows also does keyboard buffering on a higher level.
The best way seems to be to eat any arriving char while a specific flag is set. As SLaks suggests I would set KeyPreview
to true and set e.Handled
to true either in KeyPress
or in KeyDown
.. should make no difference.