USB条码扫描器和WM_KEYDOWN [英] USB Barcode Scanner and WM_KEYDOWN

查看:99
本文介绍了USB条码扫描器和WM_KEYDOWN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个可以读取条形码扫描仪的程序.另外,即使应用程序不是焦点对准的窗口(例如,在系统托盘中运行),我也需要它来读取输入.

I am trying to write a program that can will read a barcode scanner. In addition, I need it to read the input even when the application is not the window in focus (i.e., running in system tray, etc).

我找到了这篇文章,标题为

I found this article, titled Distinguishing Barcode Scanners from the Keyboard in WinForms, that seems to solve the exact problem. It is working pretty good, it detects my device and handles the WM_INPUT message.

但是,它正在检查RAWINPUT.keyboard.Message是否为WM_KEYDOWN(0x100).似乎从来没有收到过.我在

However, it is checking to see if the RAWINPUT.keyboard.Message is WM_KEYDOWN (0x100). It never seems to receive this. The only line of code I've altered in the code provided in the article is adding a Console.Out.WriteLine to output the actual values of that message:

Console.Out.WriteLine("message: {0}", raw.keyboard.Message.ToString("X"));
if (raw.keyboard.Message == NativeMethods.WM_KEYDOWN)
{
    ....

这是它的输出:

message: B
message: 1000B
message: 3
message: 10003
message: 8
message: 10008
message: 3
message: 10003
message: 5
message: 10005
message: 3
message: 10003
message: 8
message: 10008
message: 8
message: 10008
message: 4
message: 10004
message: 9
message: 10009
message: 9
message: 10009
message: 3
message: 10003

我期望在正确完成时会收到的值是:

The value I'm expecting to receive when this completes correctly is:

257232709

我通过扫描到记事本进行了验证.

Which I verified by scanning to notepad.

我不知道操作系统是否与此处相关,但是我想我应该提到我正在Windows 7 64,Visual Studio 2010和.NET Framework 3.5中运行它.扫描仪是USB条形码扫描仪,符号LS2208,设置为"HID键盘仿真"

I don't know if the Operation System is relevant here, but I figured I should mention that I'm running this in Windows 7 64 and Visual Studio 2010 and .NET Framework 3.5. Scanner is a USB Barcode Scanner, Symbol LS2208, setup as "HID KEYBOARD EMULATION"

推荐答案

仅想添加一下,Microsoft POS.net是Microsoft提供的用于构建服务点系统的免费库,它使您可以读取最常见的条形码扫描仪,并且扫描条形码时为您提供一个事件.该库是免费的,并且受到很好的支持,并且可以与任何具有OPOS驱动程序的条形码扫描仪一起使用.

just wanted to add, that microsoft POS.net, a free library from microsoft for building point of service systems, allows you to read most common barcode scanners, and gives you an event when a barcode is scanned. The library is free, and pretty well supported, and works with any barcode scanner that has an OPOS driver.

这篇关于USB条码扫描器和WM_KEYDOWN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆