处理 USB 条码扫描仪充当键盘,并在表单上的任何位置提供页眉/拖尾
在 winforms 应用程序中,我需要从标准 USB 条形码扫描仪读取输入,该扫描仪使其自身在 Windows 中显示为 USB 键盘。这必须在不将焦点集中到特定控件的情况下起作用(即,我不能说“单击此文本框然后扫描条形码”)。扫描仪配置为向其扫描的每个代码输出标头和标尾。
我宁愿不采用“原始”方式,即直接挂钩到 USB 输入或 Windows 事件(WM_INPUT 等)。
我当然可以在 ProcessCmdKey 中捕获击键,但是我似乎无法正确识别标题/尾部的键(分别为 ^~{ 和 }~^ )。
知道如何在托管代码中正确完成此操作吗?
In a winforms app, I need to read input from a standard USB barcode scanner, one which makes iteself appears as a USB keyboard to windows. This has to work without giving focus to a particular control (ie, I can't say "click on this textbox then scan the barcode"). The scanner is configured to output a header and trailer to every codes it scans.
I'd rather don't go the "raw" way, ie, hooking directly into the USB input or Windows events (WM_INPUT and such).
I can of course trap the keystrokes in ProcessCmdKey, but then I don't seem to be able to properly identify the keys for the header/trailer (^~{ and }~^ respectively).
Any idea how this can be done properly in managed code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这可行,但有点难看:
This works, but it's kinda ugly:
ProcessCmdKey 是执行此操作的正确位置。
ProcessCmdKey is the right place to do it.
也许是一个被面板隐藏的文本框,在扫描条形码时获得焦点,然后使用 keydown 事件,这应该会得到扫描仪发送的字符的原始 ascii 值
maybe a textbox hidden by a panel, that gets focus when the barcode is to be scanned, and then use the keydown event, that should get you the raw ascii values of the characters sent by the scanner