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

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

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 Report

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 Report

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