The barcode device behaves like a keyboard. When you have focus in the text box, it sends characters to the text box, as if you entered them from the keyboard.
If you do not want to use a text field, you need to subscribe to the keyboard event handler to capture the barcode stream.
Form1.InitializeComponent ():
this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.Form1_KeyPress);
Handler and supporting elements:
DateTime _lastKeystroke = new DateTime(0); List<char> _barcode = new List<char>(10); private void Form1_KeyPress(object sender, KeyPressEventArgs e) {
You will need to monitor the “keystrokes” and follow the “carriage return” that is sent with the barcode stream. This can easily be done in an array. To distinguish between keystrokes on a keyboard and keystrokes on a barcode, you can use one of the tricks you can do is keep track of the keystrokes.
For example, if you get a stream of keystrokes less than 100 ms, ending with a carriage return, you can assume that this is a barcode and a process, respectively.
Alternatively, if your barcode scanner is programmed, you can also send special characters or sequences.
ltiong_sh
source share