USB Barcode Scanner and WM_KEYDOWN

Posted by Bryce Fischer on Stack Overflow See other posts from Stack Overflow or by Bryce Fischer
Published on 2010-05-15T21:03:39Z Indexed on 2010/05/16 3:50 UTC
Read the original article Hit count: 541

Filed under:
|
|
|
|

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.

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)
{
    ....

Here 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'm expecting to receive when this completes correctly is:

257232709

Which I verified by scanning to notepad.

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"

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET