title: Get data from barcode reader without textbox
body: <p>My barcode reader is a <a href="http://en.wikipedia.org/wiki/Human_interface_device" rel="nofollow noreferrer">HID</a> type and use the USB.</p>
  
  <p>I can get the data when the text box is focus and do some business logic. </p>
  
  <pre><code> private void Form1_KeyUp(object sender, KeyEventArgs e)
   {
       if (e.KeyValue == (char)Keys.Return)
       {
             e.Handled = true;
  
             int barcodeLength = textBox1.TextLength;
  
             textBox1.Select(0, barcodeLength);
  
             queryData(textBox1.Text);    
       }
   }
  </code></pre>
  
  <p>After I google, I found this <a href="https://stackoverflow.com/questions/10850050/get-barcode-reader-value-form-background-monitoring">article</a> and try to implement to my application. But the problem now, the value return with double character. If string is F1234, it will return FF11223344 and so on.</p>
  
  <p>Here the code      </p>
  
  <pre><code>    DateTime _lastKeystroke = new DateTime(0);
      List&lt;char&gt; _barcode = new List&lt;char&gt;(10);
  
       public Form1()
       {
            InitializeComponent();
            this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.Form1_KeyPress);
       }
  
       private void Form1_KeyPress(object sender, KeyPressEventArgs e)
       {
           // check timing (keystrokes within 100 ms)
           TimeSpan elapsed = (DateTime.Now - _lastKeystroke);
           if (elapsed.TotalMilliseconds &gt; 100)
            _barcode.Clear();
  
           // record keystroke &amp; timestamp
            _barcode.Add(e.KeyChar);
            _lastKeystroke = DateTime.Now;
  
           // process barcode
           if (e.KeyChar == 13 &amp;&amp; _barcode.Count &gt; 0)
           {
               string msg = new String(_barcode.ToArray());
               queryData(msg);
               _barcode.Clear();
           }
        }
  </code></pre>
  
  <p>Need advice to solve my problem</p>