title: Java swt KeyListener "solution" barcode reading
body: <p>I found some good Q/A here on my problem but couldn't find the right one.</p>
  
  <p>I have a <a href="http://www.honeywellaidc.com/en-US/Pages/Product.aspx?category=hand-held-barcode-scanner&amp;cat=HSM&amp;pid=5145" rel="nofollow noreferrer">barcode reader</a> that reads barcode and sends scanned code as keyboard input. It is alright I can catch input easily</p>
  
  <pre><code>browser.addKeyListener(new KeyAdapter() {   
      @Override public void keyPressed(KeyEvent e) {
          if(e.keyCode &gt;=48 &amp;&amp; e.keyCode &lt;=57) {
              System.out.println("number caught");
          } 
      }
  });
  </code></pre>
  
  <p>But I will have more inputs in my application so I need to know if it is send by barcode reader or by keyboard. 
  I think it can be achieved by adding some timer in code that verifies how long is some "sequence" reading.</p>
  
  <p>I just can not figure it out, (I mean logic behind it), I am missing piece of logic.</p>
  
  <ol>
  <li>User is typing some info, (alpha numerical)</li>
  <li>user desides to use barcode reader to read barcode</li>
  </ol>
  
  <p>I tried timer e.g 
  <code>if(System.currentTimeMillis() - lastPressProcessed ??? 500) {</code> after keyListener is triggered but I think I am missing something.</p>
  
  <p><em>sidenote:</em>
  USB barcode reads code fast so keystrokes are emulated really fast est whole barcode is written in about 1 second + carry <code>/r/n</code> (also <code>enter</code> is pressed). </p>
  
  <p><em>sidenote2:</em> barcodes are going to be different in length so I can not read just some length in short time and decide wether it is user input or barcode input (max numbers read  13 + <code>enter</code>).</p>
  
  <p><em>sidenote3:</em> I have no input field for barcode I am trying to achieve running it on "background".</p>
  
  <p>I am seeking <strong>logic/pseudocode suggestions</strong> on topic.</p>
  
  <p>related topics that are really close to mine are <a href="https://stackoverflow.com/a/5199636/1564365">here</a>, and <a href="https://stackoverflow.com/a/6969324/1564365">here</a></p>
  
  <p>Thank you.</p>
  
  <p><strong>edit</strong></p>
  
  <p>After deep tought I found out the solution I'll keep this Q here just for another users that might find this usable.</p>
  
  <p><strong>solution</strong>
  --moved to answer + edited</p>