如何检查用户输入是来自条码扫描仪还是键盘?

发布于 2024-10-18 22:39:52 字数 388 浏览 1 评论 0原文

我正在为一家自助餐厅公司创建一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

心清如水 2024-10-25 22:39:52

您可以监控输入代码所需的时间。读者输入代码的速度比人类输入代码的速度快得多。

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.

阳光下慵懒的猫 2024-10-25 22:39:52

如果您可以修改扫描仪配置,则可以向扫描数据添加一些前缀/后缀。然后在代码中您可以检测到那些添加的字符。

如果你不能,那么唯一的方法是艾哈迈德的 - 测量数据输入的时间。

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.

格子衫的從容 2024-10-25 22:39:52

使用 RAW 输入 API 相对容易完成。

看看“区分条形码扫描仪与 WinForms 中的键盘"

我有一个程序,可以读取 3 个不同的 USB 扫描仪并将输入重定向到 3 个不同的“通道”进行处理。代码有点长,所以我不会在这里发布。
如果您愿意,我可以粘贴其中的一些部分或通过电子邮件将项目发送给您。

作为线索的是导入:

#region Raw Input API

[DllImport( "User32.dll" )]
extern static uint GetRawInputDeviceList( IntPtr pRawInputDeviceList, ref uint uiNumDevices, uint cbSize );

[DllImport( "User32.dll" )]
extern static uint GetRawInputDeviceInfo( IntPtr hDevice, uint uiCommand, IntPtr pData, ref uint pcbSize );

[DllImport( "User32.dll" )]
extern static bool RegisterRawInputDevices( RAWINPUTDEVICE[ ] pRawInputDevice, uint uiNumDevices, uint cbSize );

[DllImport( "User32.dll" )]
extern static uint GetRawInputData( IntPtr hRawInput, uint uiCommand, IntPtr pData, ref uint pcbSize, uint cbSizeHeader );

#endregion

InputDevice 添加到项目后,您可以通过以下方式侦听事件:

// Create a new InputDevice object and register InputDevice KeyPressed event handler.
input_dev = new InputDevice( Handle );
input_dev.KeyPressed += new InputDevice.DeviceEventHandler( m_KeyPressed );

事件处理程序 m_KeyPressed 让您可以通过 来区分您的设备>e.Keyboard.SubClass

private void m_KeyPressed( object sender, InputDevice.KeyControlEventArgs e )
{
    // e.Keyboard.SubClass tells you where from the event came.
    // e.Keyboard.key gives you the input data.
}

希望有所帮助。

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:

#region Raw Input API

[DllImport( "User32.dll" )]
extern static uint GetRawInputDeviceList( IntPtr pRawInputDeviceList, ref uint uiNumDevices, uint cbSize );

[DllImport( "User32.dll" )]
extern static uint GetRawInputDeviceInfo( IntPtr hDevice, uint uiCommand, IntPtr pData, ref uint pcbSize );

[DllImport( "User32.dll" )]
extern static bool RegisterRawInputDevices( RAWINPUTDEVICE[ ] pRawInputDevice, uint uiNumDevices, uint cbSize );

[DllImport( "User32.dll" )]
extern static uint GetRawInputData( IntPtr hRawInput, uint uiCommand, IntPtr pData, ref uint pcbSize, uint cbSizeHeader );

#endregion

After you add the InputDevice to your project, you can listen to events by:

// Create a new InputDevice object and register InputDevice KeyPressed event handler.
input_dev = new InputDevice( Handle );
input_dev.KeyPressed += new InputDevice.DeviceEventHandler( m_KeyPressed );

The event handler m_KeyPressed lets you to distinguish your devices through e.Keyboard.SubClass

private void m_KeyPressed( object sender, InputDevice.KeyControlEventArgs e )
{
    // e.Keyboard.SubClass tells you where from the event came.
    // e.Keyboard.key gives you the input data.
}

Hope to have helped.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文