Guest User

Untitled

a guest
Dec 13th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. DateTime _lastKeystroke = new DateTime(0);
  2. List<char> _barcode = new List<char>(10);
  3.  
  4. private void Form1_KeyPress(object sender, KeyPressEventArgs e)
  5. {
  6. // check timing (keystrokes within 100 ms)
  7. TimeSpan elapsed = (DateTime.Now - _lastKeystroke);
  8. if (elapsed.TotalMilliseconds > 100)
  9. _barcode.Clear();
  10.  
  11. // record keystroke & timestamp
  12. _barcode.Add(e.KeyChar);
  13. _lastKeystroke = DateTime.Now;
  14.  
  15. // process barcode
  16. if (e.KeyChar == 13 && _barcode.Count > 0) {
  17. string msg = new String(_barcode.ToArray());
  18. MessageBox.Show(msg);
  19. _barcode.Clear();
  20. }
  21. }
  22.  
  23. // Pseudo code (could be Web, Windows etc)
  24. public void Form1_Load()
  25. {
  26. txtBarcodeScanner.Top = -10000;
  27. txtBarcodeScanner.Left = -10000;
  28. txtBarcodeScanner.Width = 10;
  29. txtBarcodeScanner.Height = 10;
  30. txtBarcodeScanner.Focus();
  31. }
  32.  
  33. private void textbox_Keydown(object sender, KeyEventArgs e)
  34. {
  35. if(e.KeyCode == Keys.F12){
  36. Textbox.Focus();
  37. }
  38. if(e.KeyCode == Keys.Enter){
  39. /// after enter barcode
  40. /// save
  41. }
  42.  
  43. }
Add Comment
Please, Sign In to add comment