C# 条码扫描 Usb接口

时间:2020-10-03 10:33:51
【文件属性】:

文件名称:C# 条码扫描 Usb接口

文件大小:54KB

文件格式:ZIP

更新时间:2020-10-03 10:33:51

C# 条码扫描 Usb接口

private int KeyboardHookProc(int nCode, Int32 wParam, IntPtr lParam) { if (nCode == 0) { EventMsg msg = (EventMsg)Marshal.PtrToStructure(lParam, typeof(EventMsg)); if (wParam == 0x100)//WM_KEYDOWN=0x100 { barCode.VirtKey = msg.message & 0xff;//虚拟吗 barCode.ScanCode = msg.paramL & 0xff;//扫描码 StringBuilder strKeyName = new StringBuilder(225); if (GetKeyNameText(barCode.ScanCode * 65536, strKeyName, 255) > 0) { barCode.KeyName = strKeyName.ToString().Trim(new char[] { ' ', '\0' }); } else { barCode.KeyName = ""; } byte[] kbArray = new byte[256]; uint uKey = 0; GetKeyboardState(kbArray); if (ToAscii(barCode.VirtKey, barCode.ScanCode, kbArray, ref uKey, 0)) { barCode.Ascll = uKey; barCode.Chr = Convert.ToChar(uKey); } TimeSpan ts = DateTime.Now.Subtract(barCode.Time); if (ts.TotalMilliseconds > 50) {//时间戳,大于50 毫秒表示手动输入 strBarCode = barCode.Chr.ToString(); } else { if ((msg.message & 0xff) == 13 && strBarCode.Length > 3) {//回车 barCode.BarCode = strBarCode; barCode.IsValid = true; } strBarCode += barCode.Chr.ToString(); } barCode.Time = DateTime.Now; if (BarCodeEvent != null) BarCodeEvent(barCode);//触发事件 barCode.IsValid = false; } } return CallNextHookEx(hKeyboardHook, nCode, wParam, lParam); }


【文件预览】:
USBTiaomaSaoMiao
----C#SaomiaoTest()
--------SaomiaoTest2.sln(878B)
--------SaomiaoTest2()
--------SaomiaoTest2.suo(26KB)

网友评论