Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

147
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!