title: Differentiating input from 2 separate keyboards
body: <p>All,</p>
  
  <p>Apologies in advance if this is an ill-informed question with lack of detailed examples of what I have tried to do so far - all the material I am finding on this topic seems to be out of scope of what I'm trying to do, or its just going right over my head (Learning resources on this are welcome!!).</p>
  
  <p>What I am essentially trying to do is build a small program that will differentiate the input device used to create a user input on my Lenovo Win10 Machine that can run in the background and trigger scripts when certain conditions are met. In my case the input devices are a generic wireless/USB keyboard, and a USB Barcode scanner that acts as a HID Keyboard (The Barcode Scanners plugs directly into the machine, not via a keyboard). </p>
  
  <p>The reason I need to differentiate the input is for example, if I have a script run every time an asterisk is printed from a scanned barcode I want the user to still be able to type an asterisk from the keyboard without triggering the script - Im restricted to using Code 128 barcodes so I also cant bypass this issue by adding characters to the barcodes to trigger the scripts that are not present on the keyboard.</p>
  
  <p>In pseudo-code its essentially</p>
  
  <pre><code>start:
  if inputdevice == keyboard 1
      then
          System.Diagnostics.Process.Start(myBatchFileName);
      else
          goto start;
  </code></pre>
  
  <p>Initially I tried to do this in VB, using some code I had previously used to listen to a COM Port to record output from an arduino -</p>
  
  <pre><code>Dim barcodescanner As SerialPort   
  barcodescanner = New SerialPort()
  
  barcodescanner.PortName = "COMx"   
  barcodescanner.BaudRate = 9600      
  barcodescanner.Parity   = Parity.None     
  barcodescanner.DataBits = 8             
  barcodescanner.StopBits = StopBits.One  
  Dim barcode As String          
  
  barcodescanner.Open()                    
  barcode = barcodescanner.ReadLine()  
  barcodescanner.Close() 
  </code></pre>
  
  <p>-however for reasons beyond me I cannot successfully use a virtual COM port for the scanner and record data this way, I also tried to create a virtual COM port using drivers from <a href="http://www.ftdichip.com/FTDrivers.htm" rel="nofollow noreferrer">http://www.ftdichip.com/FTDrivers.htm</a> but this was to no avail.</p>
  
  <p>From some investigation I found some C# Classes, namely; InputEventArgs, InputDevice, RoutedEventArgs, that seem as if they could be used to resolve a device ID from an Input/Event that may allow be to harness some information I could use to flesh out and build the pseudo IF THEN ELSE loop above - but im struggling to use the classes and actually build any working code.</p>
  
  <p>Does anyone have any suggestions as to how to do this?</p>
  
  <p>In a perfect world if I could create a virtual COM port for the barcode scanner and listen to it using VB that would be ideal - but if not could anyone suggest a method of doing this in C# or point me to another method?</p>