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:
- this.destroyListener = this.eventManager.addGlobalEventListener('window', 'keydown', (e) => {
- nextCode = window.event ? e.keyCode : e.which;
- 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 };
- nextCode = codes[nextCode];
- nextTime = new Date().getTime();
- if (lastCode == null && lastTime == null) {
- barcode = String.fromCharCode(nextCode);
- }
- else if (lastCode != null && lastTime != null && (nextTime - lastTime) <= 30) {
- barcode += String.fromCharCode(nextCode);
- }
- else {
- barcode = "";
- lastCode = "";
- lastTime = null;
- }
- lastCode = nextCode;
- lastTime = nextTime;
- });
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
1 Replies
Device:tc51