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

173
Views
Javascript Key Mapping for number

I made a shortcut in my website

alt + 1 = something()
alt + 2 = something()
shift + 1 = something()
...

window.addEventListner("keydown",(e) => {
if(e.key === 1 && e.alt) doSomething(); 
})

But the problem is when i press shift+1 it become shift + ! the key become special char! And alt(option) + 1 is ¡
Should i make a Key Map for every special chars? Or is there good other way ?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use the code property and look for the string "Digit1". That's the purpose of code, to give you a key name unaffected by modifier keys.

Here's a demo of the difference:

window.addEventListener("keydown",(e) => {
    console.log(`key = ${e.key}, code = ${e.code}`);
});
Click here, then press 1, and then press !.

So for instance:

if (e.altKey && e.code === "Digit1") {
    // ...
}

(Note that it's altKey, not alt, to see if the Alt key is down.)

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!