Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

156
Vistas
How to handle shift pressed before another key in onkeyup?

I need to handle usb barcode scanner in my web page, all was working well on my computer but when i tried it on another one (Windows 7 and another scanner) i had an issue with shift key.

The scanner barcode has : symbol and when it's read it's passed like Shift; how can i get the real symbol from it?

Here is my function when i handle the scanning:

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;
    }
  }
});

Here is how the scanner barcode result in notepad (and that's how it should be) and under you can find how it looks like in the browser:

enter image description here

TEST TEXT:

WRONG

Hc1ò6BFOXN%Ts3DHPVo13j -g'-2YRVa.q-r8'd32Fc1j9M$Di9CPi9ELNLAPS$SçLc-GPWBILc9Ff9

84Ev28JVSAp921TDUMx6WUKAMa800p92ò3

RIGHT

HC1ç6BFOXN%TS3DHPVO13J -G'-2YRVA.Q-R8'D32FC1J9M$DI9CPI9ELNLAPS$SçLC-GPWBILC9FF9

(4EV28JVSAP921TDUMX6WUKAMA800P92ç3

ENG KEYBOARD

HC1:6BFOXN%TS3DHPVO13J /G-/2YRVA.Q/R8-D32FC1J9M$DI9CPI9ELNLAPS$S:LC/GPWBILC9FF9

*4EV28JVSAP921TDUMX6WUKAMA800P92:3
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Solved by replacing keyup with keypress

Now the code looks like this:

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;
    }
  }
});
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda