c#USB扫描枪,防止输入框手动输入

 private void txtScan_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (string.IsNullOrEmpty(txtScan.Text))
            {
                startInput = DateTime.Now;
            }

            if (e.KeyChar == Convert.ToChar(Keys.Enter))
            {
                //判断回车键业务处理
            }
            else
            {
                if ((startInput.Ticks + 5000000) > DateTime.Now.Ticks)
                {
                    txtScan.Text += e.KeyChar;
                }
                else
                {
                    txtScan.Text = "";
                }
            }
        }
原文地址:https://www.cnblogs.com/weifeng123/p/12515554.html