Texbox输入,禁用键盘,保持了条码扫描器 [英] Texbox input, disable for keyboard, keep for barcode scanner

查看:934
本文介绍了Texbox输入,禁用键盘,保持了条码扫描器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与一个文本框一个Windows窗体应用程序。我将迫使用户使用条形码扫描器,所以键盘输入应禁用。 keyPressed事件不起作用,因为也由条形码扫描器禁用输入。

I have made a Windows Form application with a textbox. I will force users to use the barcode scanner, so the keyboard input should be disabled. The KeyPressed event does not work, because is also disabled input from the barcode scanner.

我想也许我可以设置TextChanged事件计时器,但我真的不知道它是如何工作的。

I thought maybe I can set a timer on the TextChanged event, but I do not really know how it works.

让别人一个好主意?

推荐答案

根据您的描述,我认为你的条码扫描器是HID条形码扫描仪。如果是这样,有没有简单的答案在这里,因为条形码扫描仪功能就像一个键盘。 。禁用键盘输入将禁用条形码扫描器

Based on your description, I assume that your barcode scanner is an HID barcode scanner. If so, there is no easy answer here because the barcode scanner functions exactly like a keyboard. Disabling keyboard input will disable the barcode scanner.

我以前做过这一点,有几个解决方案,我所知道的:

I have done this before, and there are a few solutions I know of:


  1. 使用条形码扫描仪,是不是HID条形码扫描仪。例如:串口,或者类似的东西

  2. 配置条形码扫描器在条形码扫描的开始和结束时发送特殊字符。 (这是后话,如果你有条形码扫描仪的特定型号的说明书,你可以做。)撰写您的keyPressed事件侦听这些特殊字符作为一个信号,它是从条形码扫描仪获取数据。当它看到他们,启用和禁用文本框。

  3. 使用Windows API调用直接与条形码扫描仪进行通信。这需要知道VID和条形码扫描仪的PID,而像GetRawInputDeviceInfo,GetRawInputData和RegisterRawInputDevices的API的一些详细知识。这是非常强大的,因为你可以从应用程序的任何地方接收条形码输入,但它是非常复杂的。

然而,一个警告:你可能不希望在所有禁用的文本框中。如果什么条形码已损坏,扫描仪无法读取呢?你总是希望用户能够手动输入条码。下一次你去通过收银机在商店,发现总有手动输入条码的一种方式。

However, one caveat: You probably don't want to disable the text box at all. What if the barcode is damaged and the scanner cannot read it? You always want the user to be able to manually enter the barcode. Next time you go through the cash register at a store, notice that there is always a way to manually enter the barcode.

这篇关于Texbox输入,禁用键盘,保持了条码扫描器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆