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

174
Vistas
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 Respuestas
Responde la pregunta

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 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