title: barcode scanner produces a "keypress" event only when the user is on an input box. What event to listen to when user is not on an input box?
body: <p><em>Context</em>:</p>
  
  <p>I'm working on a web application that uses a barcode scanner device. Users scan barcodes, I redirect them to the appropriated page. </p>
  
  <p><em>Problem</em>:</p>
  
  <p>The scan device I'm using triggers "keypress" events ONLY when the user is in a input box element</p>
  
  <pre><code>window.addEventListener("keypress", function (event) {
      // do something with the event
  }
  </code></pre>
  
  <p>I would like to be able to scan barcodes from ANYWHERE in my application (even when I'm not in an input box). (Yes I know that the code above will fire for every character, I have a timer based algorithm to know if it's a barcode reader or a person typing.). </p>
  
  <p><em>So far</em> :</p>
  
  <p>I looked at <a href="https://stackoverflow.com/questions/11290898/detect-when-input-box-filled-by-keyboard-and-when-by-barcode-scanner">this</a>, so I tried to replace the accepted solution's selector with a more general selector (window or document) without luck. Is there other events more appropriated for this task? I'm open to suggestions on doing it another way.</p>
  
  <p><em>--EDIT--</em> :</p>
  
  <p>After more research I came across <a href="https://stackoverflow.com/questions/43981445/javascript-catch-input-when-no-input-has-focus">this</a>. The problem is that my view might not have any input. Just plain text</p>
  
  <p>Thank you</p>