USB Barcode Scanner & WM_KEYDOWN

I am trying to write a program that can read a barcode scanner. Also, I need it to read input even if the application is not the focus of the window (i.e. runs in the system tray, etc.).

I found this article titled Distinguishing Barcode Scanners from Keyboard in WinForms , which seems to solve the exact problem. It works really well, it detects my device and handles the WM_INPUT message.

However, it does check if RAWINPUT.keyboard.Message is WM_KEYDOWN (0x100). It doesn't seem to be the case. The only line of code that I have changed in the code presented in the article is to add Console.Out.WriteLine to output the actual values ​​this message:

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

      

This is what it outputs:

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 expect to get when this is done correctly:

257232709

      

Which I checked by scanning to notepad.

I don't know if the Operating System is applicable here, but I figured I should mention that I am running this on Windows 7 64 and Visual Studio 2010 and .NET Framework 3.5. The scanner is a USB barcode scanner, Symbol LS2208, configured as "HIDDEN KEYBOARD EMULATION"

+2


a source to share


3 answers


just wanted to add that microsoft POS.net, a free library from Microsoft for creating points of service, allows you to read the most common barcode scanners and gives you a barcode scan event. The library is free and fairly well supported, and works with any barcode scanner that has an OPOS driver.



+3


a source


One non-software solution that could save you a lot of time would be to get an RS-232 cable for this scanner and just read from the COM port. Then you don't need to worry about which window or control has focus. This particular scanner has a COM port emulation emulator, although it probably won't work under Windows 7.



0


a source


It occurred to me that I really don't need the solution this article solves. After reading a few times, I realized that it is designed to handle a situation where you cannot configure the scanner to use a prefix and suffix. Lucky for me, I can do it.

Otherwise, I contacted the author of the article, and we believe that the problem is related to the fact that I was running Windows 64. I think that some of the code is using the wrong data types, which can cause the 64-bit code to be wrong placed for data ... I wasn However it can be checked.

Was a great exercise in programming low-level windows. Great resource at pinvoke.net for using interops ...

0


a source







All Articles