如何检查用户输入是来自条码扫描仪还是键盘?
我正在为一家自助餐厅公司创建一个 pos 应用程序,其中 收银员扫描他的员工 ID,上面会显示他的交易信息。
我的问题是,收银员也可以使用键盘进行输入(员工 ID),这是非常危险的。
if employee(true)
show employee information
then add orders
else
Exception
目前我只是从 UI 中隐藏 TexTbox
,单击 New Button
然后将光标焦点放在它上面。然后收银员扫描员工身份证。在这部分,收银员也可以通过键盘打字并继续交易。
处理这种情况的最佳方法是什么?规则是只能使用条形码扫描仪。
谢谢问候
I am creating a p.o.s application for a cafeteria company in which
the cashier scans his employee ID and it shows his information for the transaction.
My Problem is, the cashier can also use their keyboard for their input (employee ID) which is very risky.
if employee(true)
show employee information
then add orders
else
Exception
Currently I just hide TexTbox
from the UI, click New Button
then set cursor focus on it. Then cashier scans employee id. In this part, the cashier can also type via keyboard and continue transaction.
What is the best way to handle this scenario? The rule is only barcode scanner must be use.
Thanks in regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以监控输入代码所需的时间。读者输入代码的速度比人类输入代码的速度快得多。
You could monitor the time it took for the code to be entered. A reader would enter the code much faster than a human typing it in.
如果您可以修改扫描仪配置,则可以向扫描数据添加一些前缀/后缀。然后在代码中您可以检测到那些添加的字符。
如果你不能,那么唯一的方法是艾哈迈德的 - 测量数据输入的时间。
If you have the possibility to modify the scanner configuration you can add some prefix/suffix to the scanned data. Then in the code you can detect those added characters.
If you can't, then only way is Ahmed's - measuring the time of data entry.
使用 RAW 输入 API 相对容易完成。
看看“区分条形码扫描仪与 WinForms 中的键盘"
我有一个程序,可以读取 3 个不同的 USB 扫描仪并将输入重定向到 3 个不同的“通道”进行处理。代码有点长,所以我不会在这里发布。
如果您愿意,我可以粘贴其中的一些部分或通过电子邮件将项目发送给您。
作为线索的是导入:
将
InputDevice
添加到项目后,您可以通过以下方式侦听事件:事件处理程序
m_KeyPressed
让您可以通过来区分您的设备>e.Keyboard.SubClass
希望有所帮助。
It is relatively easy done with RAW Input API.
Take a look at "Distinguishing Barcode Scanners from the Keyboard in WinForms"
I have a program that reads 3 different USB scanners and redirects the input to 3 different "channels" for processing. The code is somewhat extensive, so I am not postin it here.
If you wish, I can paste some chunks of it or send you the project in e-mail.
As a clue are the imports:
After you add the
InputDevice
to your project, you can listen to events by:The event handler
m_KeyPressed
lets you to distinguish your devices throughe.Keyboard.SubClass
Hope to have helped.