Scan listening issue

J Jason Kang 1 year 4 months ago
156 1 0

Hi all,


 I use Angular created one web application with PWA and install on my Zebra device.
 I want to get barcode value from device scan on my app screen.
 If I use <input /> component will get the scan value as normal.
 But I'd like to get the value through event listening without <input /> component, it always failed.
 I added event listener like this:

  1.  this.destroyListener = this.eventManager.addGlobalEventListener('window', 'keydown', (e) => {
  2.      nextCode = window.event ? e.keyCode : e.which;
  3.      const codes = { '48': 48, '49': 48, '50': 50, '51': 51, '52': 52, '53': 53, '54': 54, '55': 55, '56': 56, '57': 57, '65': 'A', '66': 'B', '96': 0, '97': 1, '98': 2, '99': 3, '100': 4, '101': 5, '102': 6, '103': 7, '104': 8, '105': 9 };
  4.      nextCode = codes[nextCode];
  5.      nextTime = new Date().getTime();
  6.      if (lastCode == null && lastTime == null) {
  7.         barcode = String.fromCharCode(nextCode);
  8.      }
  9.      else if (lastCode != null && lastTime != null && (nextTime - lastTime) <= 30) {
  10.          barcode += String.fromCharCode(nextCode);
  11.     }
  12.    else {
  13.     barcode = "";
  14.     lastCode = "";
  15.     lastTime = null;
  16.  }
  17. lastCode = nextCode;
  18. lastTime = nextTime;
  19. });

It can get the barcode value which has only one character, like 'A' or '1', but failed to long string, like 'ABC' or 'A1234'
Maybe I missed some settings.

Thanks in advance.

 Jason
       

CONTACT
Can’t find what you’re looking for?