Cri*_*and 8 c# io barcode-scanner winforms
我现在正在为公司自助餐厅创建pos应用程序,收银员扫描员工ID并显示其交易信息.
我的问题是收银员也可以使用他们的键盘输入(Employeeid),这是非常危险的.
if employee(true)
show employee information
then add orders
else
Exception
Run Code Online (Sandbox Code Playgroud)
处理这种情况的最佳方法是什么?规则只是必须使用条形码扫描仪.
谢谢你的问候
j4x*_*j4x 11
使用RAW Input 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
Run Code Online (Sandbox Code Playgroud)
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 );
Run Code Online (Sandbox Code Playgroud)
事件处理程序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.
}
Run Code Online (Sandbox Code Playgroud)
希望有所帮助.
| 归档时间: |
|
| 查看次数: |
31589 次 |
| 最近记录: |