Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It is relatively easy done with RAW Input API.</p> <p>Take a look at "<a href="http://web.archive.org/web/20150316093927/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>"</p> <p>I have a program that reads 3 different USB scanners and redirects the input to 3 different "channels" for processing. The code is somewhat extensive, so I am not postin it here. If you wish, I can paste some chunks of it or send you the project in e-mail.</p> <p>As a clue are the imports:</p> <pre><code>#region Raw Input API [DllImport( "User32.dll" )] extern static uint GetRawInputDeviceList( IntPtr pRawInputDeviceList, ref uint uiNumDevices, uint cbSize ); [DllImport( "User32.dll" )] extern static uint GetRawInputDeviceInfo( IntPtr hDevice, uint uiCommand, IntPtr pData, ref uint pcbSize ); [DllImport( "User32.dll" )] extern static bool RegisterRawInputDevices( RAWINPUTDEVICE[ ] pRawInputDevice, uint uiNumDevices, uint cbSize ); [DllImport( "User32.dll" )] extern static uint GetRawInputData( IntPtr hRawInput, uint uiCommand, IntPtr pData, ref uint pcbSize, uint cbSizeHeader ); #endregion </code></pre> <p>After you add the <code>InputDevice</code> to your project, you can listen to events by:</p> <pre><code>// Create a new InputDevice object and register InputDevice KeyPressed event handler. input_dev = new InputDevice( Handle ); input_dev.KeyPressed += new InputDevice.DeviceEventHandler( m_KeyPressed ); </code></pre> <p>The event handler <code>m_KeyPressed</code> lets you to distinguish your devices through <code>e.Keyboard.SubClass</code></p> <pre><code>private void m_KeyPressed( object sender, InputDevice.KeyControlEventArgs e ) { // e.Keyboard.SubClass tells you where from the event came. // e.Keyboard.key gives you the input data. } </code></pre> <p>Hope to have helped.</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