Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I tell if keyboard input is coming from a barcode scanner?

On one computer I have both a regular keyboard and a barcode scanner which emulates a keyboard. When my app gets keyboard input, how can I determine whether that input is coming from the barcode scanner or the real keyboard?

like image 809
mahboub_mo Avatar asked Apr 11 '11 11:04

mahboub_mo


People also ask

How do I use a barcode scanner as a keyboard?

In order to use the Barcodescanner Keyboard you need to enable it. Do this by opening Android Settings , Language & keyboard and enable the input method named Barcode Keyboard by checking the box. Confirm the security warning (see privacy). After the input method was enabled it must be activated.

What type of input does a barcode scanner take?

A Barcode reader or Barcode scanner is an electronic input device which is able to scan and decode barcodes. These devices use optical technology such as infrared light.

Can a barcode reader be used for input and output?

Like other input devices, a barcode reader is bringing in (inputting) information from the outside world into a computer or other electronic device. If the barcode reader also has a screen that displays (outputs) results or prints results, it would be considered an input/output device.


1 Answers

You'll get input from both. Not simultaneously, of course. It will all be placed into a queue, but Windows will process key events from both keyboards.

Don't be helpless, though. As David Heffernan suggests, you can easily figure this out yourself by plugging in both keyboards to your computer, opening up Notepad, and typing random characters to see which one generates input.

You reply that you want to "check that with C# code", but I have no idea what that means. How about creating a console app that reads input from the keyboard and displays it on the screen?

using System;

class AdvancedKeyboardTester
{
   static void Main(string[] args)
   {
      for (; ;)
      {
         Console.ReadKey();
      }
   }
}

Press Ctrl+C when you tire of the fun and want to quit the program.


Edit: It sounds like you're looking for the RegisterRawInputDevices function, which allows you to enable raw input for all of your keyboards, and then enumerate through the results to determine which device sent the message.

Fortunately, it looks like someone has already written a C# wrapper library for this, available for download on Code Project: Using Raw Input from C# to handle multiple keyboards


Edit 2: (it seems the information just keeps tricking in from the comments)

If you're using a barcode scanner, this gets a lot easier. Because they're explicitly designed for this purpose, they're almost all programmable. Meaning that you can tell them to prefix (and/or suffix) their input with some sentinel characters that indicate the input is coming from the barcode scanner, rather than a standard keyboard. (Check your barcode scanner's user manual for more information.) Then, all you have to do is filter out the keyboard input based on the presence or absence of those sentinel characters. You can also check for how quickly the characters between the prefix and suffix were entered.

like image 84
Cody Gray Avatar answered Oct 07 '22 17:10

Cody Gray