Identifying input from keyboard devices

  • Thread starter Thread starter Don Riesbeck Jr.
  • Start date Start date
D

Don Riesbeck Jr.

I'm working on an application (OEM) using C# that utilizes input from a
keyboard, and USB Barcode Scanner. The scanner is a HID Keyboard device,
and input from it is sent to the system as if it were a keyboard. I need to
be able to identify input from the scanner and keyboard independently. I've
looked at DirectX.DirectInput, and using user32.dll to hook into the
keyboard messages, but neither method seems to allow for identification of
the device sending the input. Inputs from either device are received and
there is not apparent difference.

Is there a way for either method (DI, or hooks) to identify which keyboard
device input is from? Or, is there another method that I overlooked?

(Note that the scanner cannot send pre-fixes, or be configured as a COM
device.)

Thanks in advance!
Don Riesbeck Jr.
 
I knew I was going to forget something: This application will be running on
Windows 2000, Windows 2000 Server and potentially Windows XP.

Thanks Again
 
Are you in control of the Barcodes? If so, you can add a special code to
every encoded string for example, supppose the user can type "PRODUCT X" or
scan "PRODUCT X", the barcode could contain this instead "XXXProduct X" and
your code could always look for the first three starting characters and if
they are XXX then you can assume they came form a scanner.

JIM
 
I wish, but unfortunatly the barcode format is configurable, and must
support third party formats that do not have prefixes.

Thanks,
Don
 
I guess you are out of luck then. Data passed in through a wedge comes into
the PC through the keyboard interupt and appears to the computer exactly as
if it were typed. You should re-evaluate your reasons for why you need to
know this, and try to find a more generic way to handle it. i.e. A message
box that states "The scanned data is incorrect" could simply state "The
input data is incorrect" and your problem is solved.

JIM
 
The Barcode scanner is not a "wedge" in the sense that it is inline with the
keyboard. The keyboard is PS/2 and the BC scanner is USB.

Our application must support input from the keyboard AND scanner. All
barcode data will be parsed by a library but keyboard input will just be
entered into the selected fields on the form.

There must be a way to at least detect that the scanner input is coming...
 
Yes, there is. You must write your own driver for the USB device driver.
Then you can do anything you want. Or obtain the API from the vendor of
that device. How do you know for sure it is USB? I thought you said that
was outside your control? If the scanner IS inside your control, then you
can add a PREFIX to the actual scanner hardware so that every bit of scanned
text is pre-pended with some special code. How do you always know it iwl be
a USB scanner and not a serial one? Or a Keyboard wedge? Again, I would
ask what is your business case for needing to know? You will most likely
need to re-design your app.

JIM
 
I meant the barcodes themselves are outside of our control. (they are
supplied by vendors to our customers)

The application is a second generation of a product; we are set on the
machine, and have a couple USB scanners (we sell the whole thing.) We know
what scanners the current customers have, we sold them to them. Some of the
scanners support prefixing some don't we MUST support them all. The problem
is we have several different components which use barcodes and the code
currently used is very complicated. My hope was to have an object that just
monitored keyboard activity, and when it detected input from the barcode it
would simply set a property, and in the key pressed handler, we could just
have something like:

//Check for scan data
if (bcHook.isScan)
{
bctextBox.Text += e.KeyChar;
e.Handled = true;
return;
}

This would allow us to only worry about barcodes in the bctextBox field,
even if another textBox had focus.

I really only need to know if there was activity on the barcode scanner, I
don't need the actual data because it will come through the normal channels.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top