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

113
Vistas
Check for alt + key js

I want to see if the alt key and j(or any other number or letter) key are being pressed at the same time.

Here's what I have so far:

document.onkeydown = function(e) { 
    if(e.altKey && e.keyPressed == "j") {
        console.log("alt + j pressed")
    }
}

This isn't working.

Any help on this?

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

You should be getting the event's key property instead:

document.onkeydown = function(e) { 
    if(e.altKey && e.key == "j") {
        console.log("alt + j pressed")
    }
}

about 4 years ago · Juan Pablo Isaza Denunciar

0

Maybe it works

var altKeyPressed = false;
document.addEventListener("keydown", function(e) {if(e.altKey) {
        altKeyPressed = true;
    }});
document.addEventListener("keydown", function(e) {if(e.key === "j" && altKeyPressed) {
        console.log("alt + j pressed");
        altKeyPressed = false;
    }});
about 4 years ago · Juan Pablo Isaza Denunciar

0

That's because a KeyboardEvent does not have a keyPressed property. There is a key property that indicates which key was pressed.

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