How To Distinguish Key Event Between Keyboard And Barcode Gun
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()
}
source to share
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.
source to share
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.
source to share