How To Distinguish Key Event Between Keyboard And Barcode Gun

I need to focus on the textarea, depending on the key event I receive from the BarCode gun, instead of the keyboard event. How should I distinguish between this key event?

+2


source to share


4 answers


In my experience this is not possible.

Not without the slightest bit of magic. For example, if you scan something with a barcode writer, text is typed much faster than anyone can type, but still slower than copy / paste.

So, analyze the speed and content.



It's very easy when you want to scan verified barcodes.

last_up = 0
input_cache = ""

key_up(key) {
  if ((time.now() - last_up) > 1) {// seconds
     input_cache = ""
     last_up = 0
  } else {
    input_cache += key
    if (IsValidBarcode(input_cache)) {
      doSomething()
    }
  }
  last_up = time.now()
}

      

+4


source


Many barcode readers can be configured to send a prefix to the actual barcode content. This prefix can be either a string or specific key strokes (for example, F12or Ctrl+ B).



You can use this function to detect an incoming barcode.

+4


source


I would suggest that you cannot distinguish simply between a real keypress and a keypress event generated by the barcode gun. The bayonet gun I have is the old one that hangs between the keyboard and the PC. The PC doesn't know that the barcode gun is even there.

The only thing I would like to say is that you can parse the input stream and look for strings that are typical of a barcode. Probably not so easy.

+1


source


Is this a desktop app?

If it's a web app, the jQuery hotkeys plugin might be helpful: http://code.google.com/p/js-hotkeys/

You may not be able to isolate the difference in inputs, but I think that would be advisable.

0


source







All Articles