C# or .NET Flushing Keyboard Buffer

后端 未结 7 1413
太阳男子
太阳男子 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:12

    Disable the form, and force all processing to occur with DoEvents whilst it's disabled. The Controls should reject any keystokes because they are disabled. Then re-enable the form.

    this.Enabled = false;
    Application.DoEvents();
    this.Enabled = true;
    

提交回复
热议问题