Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DateTime _lastKeystroke = new DateTime(0);
- List<char> _barcode = new List<char>(10);
- private void Form1_KeyPress(object sender, KeyPressEventArgs e)
- {
- // check timing (keystrokes within 100 ms)
- TimeSpan elapsed = (DateTime.Now - _lastKeystroke);
- if (elapsed.TotalMilliseconds > 100)
- _barcode.Clear();
- // record keystroke & timestamp
- _barcode.Add(e.KeyChar);
- _lastKeystroke = DateTime.Now;
- // process barcode
- if (e.KeyChar == 13 && _barcode.Count > 0) {
- string msg = new String(_barcode.ToArray());
- MessageBox.Show(msg);
- _barcode.Clear();
- }
- }
- // Pseudo code (could be Web, Windows etc)
- public void Form1_Load()
- {
- txtBarcodeScanner.Top = -10000;
- txtBarcodeScanner.Left = -10000;
- txtBarcodeScanner.Width = 10;
- txtBarcodeScanner.Height = 10;
- txtBarcodeScanner.Focus();
- }
- private void textbox_Keydown(object sender, KeyEventArgs e)
- {
- if(e.KeyCode == Keys.F12){
- Textbox.Focus();
- }
- if(e.KeyCode == Keys.Enter){
- /// after enter barcode
- /// save
- }
- }
Add Comment
Please, Sign In to add comment