title: How to distinguish between android KeyEvent and external device KeyEvent
body: <p>I'm reading barcodes/cards with external device connected to android device by USB.</p>
  
  <p>External device sends it's input as KeyEvent to Activity and I can read it in <code>dispatchKeyEvent()</code> method inside <code>Activity</code> like this</p>
  
  <pre><code>@Override public boolean dispatchKeyEvent(KeyEvent event) {
      if (event.getAction() == KeyEvent.ACTION_DOWN) {
          externalDeviceService.onNewInputFromExternalDevice(((char) event.getUnicodeChar()));
      }
      return super.dispatchKeyEvent(event);
  }
  </code></pre>
  
  <p>But for example when there is focus on some <code>EditText</code>, it types external device input to that input field instead of just delegating to service.</p>
  
  <p>Is there a way to distinguish between input from android device(soft keyboard) and from external device(RFID card reader or barcode scanner)?</p>
  
  <p>Obvious solution would be <code>keyEvent.getDevice().getName()</code>, and recognize external device to handle event appropriately, but that binds me to specific devices which is huge limitation. Maybe there is a way to check if <code>KeyEvent</code> comes from android soft keyboard?</p>
  
  <p>Any insight on this would be appreciated.</p>