Note that there are some explanatory texts on larger screens.

plurals
  1. POUSB Barcode Scanner and WM_KEYDOWN
    text
    copied!<p>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).</p> <p>I found this article, titled <a href="http://nicholas.piasecki.name/blog/2009/02/distinguishing-barcode-scanners-from-the-keyboard-in-winforms/" rel="nofollow noreferrer">Distinguishing Barcode Scanners from the Keyboard in WinForms</a>, that seems to solve the exact problem. It is working pretty good, it detects my device and handles the WM_INPUT message.</p> <p>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 <a href="http://nicholas.piasecki.name/blog/2009/02/distinguishing-barcode-scanners-from-the-keyboard-in-winforms/" rel="nofollow noreferrer">article</a> is adding a Console.Out.WriteLine to output the actual values of that message:</p> <pre><code>Console.Out.WriteLine("message: {0}", raw.keyboard.Message.ToString("X")); if (raw.keyboard.Message == NativeMethods.WM_KEYDOWN) { .... </code></pre> <p>Here is what it outputs:</p> <pre><code>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 </code></pre> <p>The value I'm expecting to receive when this completes correctly is:</p> <pre><code>257232709 </code></pre> <p>Which I verified by scanning to notepad.</p> <p>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"</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload