Hello, 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 ?
I would guess that you cannot differentiate simply between a real keypress and a keypress event generated by a barcode gun. The barcode gun I have is an old one which hangs between the keyboard and the pc. The pc is not aware that the barcode gun is even there.
The only suggestion I would have is that you could analyse the input stream and look for barcode-typical strings. Probably not so easy.
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()
}
Is it a desktop application?
If it's a web application, the jQuery hotkeys plugin might be useful: http://code.google.com/p/js-hotkeys/
It may not help you isolate the difference in inputs, but I imagine it'd be worth a shot.
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.