Necesito manejar el escáner de código de barras usb en mi página web, todo funcionaba bien en mi computadora, pero cuando lo probé en otra (Windows 7 y otro escáner) tuve un problema con la tecla Mayús.
El código de barras del escáner tiene : símbolo y cuando se lee se pasa como Shift; ¿Cómo puedo obtener el símbolo real de él?
Aquí está mi función cuando manejo el escaneo:
document.addEventListener("keyup", (event) => { let key = event.key; if (event.isComposing || key === 'Shift' || key === 'Control' || key === 'Meta' || key === 'Alt') { return; } if (containerLoading.classList.contains("d-none")) { showLoading(); } if (!containerLoading.classList.contains("d-none")) { if (key === "Enter" || key === "Tab") { if (barcode != "") { websocket.send(`<ART>${barcode}</ART>`); barcode = ""; } } else { barcode += key; } } });Así es como el código de barras del escáner da como resultado el bloc de notas (y así es como debería ser) y debajo puede ver cómo se ve en el navegador:
TEXTO DE PRUEBA:
EQUIVOCADO
Hc1ò6BFOXN%Ts3DHPVo13j -g'-2YRVa.q-r8'd32Fc1j9M$Di9CPi9ELNLAPS$SçLc-GPWBILc9Ff9 84Ev28JVSAp921TDUMx6WUKAMa800p92ò3CORRECTO
HC1ç6BFOXN%TS3DHPVO13J -G'-2YRVA.Q-R8'D32FC1J9M$DI9CPI9ELNLAPS$SçLC-GPWBILC9FF9 (4EV28JVSAP921TDUMX6WUKAMA800P92ç3TECLADO ESP
HC1:6BFOXN%TS3DHPVO13J /G-/2YRVA.Q/R8-D32FC1J9M$DI9CPI9ELNLAPS$S:LC/GPWBILC9FF9 *4EV28JVSAP921TDUMX6WUKAMA800P92:3Resuelto reemplazando keyup con keypress
Ahora el código se ve así:
document.addEventListener("keypress", (event) => { let key = event.key; if (event.isComposing || key === 'Shift' || key === 'Control' || key === 'Meta' || key === 'Alt') { return; } if (containerLoading.classList.contains("d-none")) { showLoading(); } if (!containerLoading.classList.contains("d-none")) { if (key === "Enter" || key === "Tab") { if (barcode != "") { websocket.send(`<ART>${barcode}</ART>`); barcode = ""; } } else { barcode += key; } } });