C# or .NET Flushing Keyboard Buffer

后端 未结 7 1366
太阳男子
太阳男子 2021-01-12 08:34

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

7条回答
  •  臣服心动
    2021-01-12 09:09

    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.

提交回复
热议问题