Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to differentiate the key event between keyboard and bar code gun

Tags:

java

I have to set a focus on the text field depending upon the key event I get from BarCode gun instead of keyboard key event.How should I differentiate these key event ?

like image 789
om. Avatar asked Oct 24 '25 14:10

om.


2 Answers

In my experience it's not possible.

Not without a little bit wizardry. For example if you scan something with a barcode gun the text gets typed much faster than any human could possible type but still slower than copy/paste.

So analyse the speed and the content.

It gets very easy when you want to scan validatable 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()
}
like image 103
Sven Hecht Avatar answered Oct 26 '25 10:10

Sven Hecht


Many barcode readers can be configured to send a prefix before the actual content of the barcode. This prefix could either be a string, or specific key strokes (like F12 or Ctrl+B).

You can use this feature to detect an incoming barcode.

like image 30
ftl Avatar answered Oct 26 '25 11:10

ftl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!