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

149
Views
detect up/down and tab keys press in JavaScript

How can I detect if the up/down/left/right or the tab key is pressed, I tried to use the code below but it doesn't print something when those keys are pressed

document.addEventListener('keypress', (e) => {
    console.log(e.key)
})
almost 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You need to use keydown instead of keypress

document.addEventListener("DOMContentLoaded", function(event) {
   document.addEventListener('keydown', (e) => {
    console.log(e.keyCode)
   })
})

almost 4 years ago · Santiago Trujillo Report

0

document.onkeydown = checkKey;

function checkKey(e) {

    e = e || window.event;

    if (e.keyCode == '38') {
        console.log("up arrow")// up arrow
    }
    else if (e.keyCode == '40') {
        console.log("down arrow")// down arrow
    }
    else if (e.keyCode == '9') {
       console.log("tab")// tab
    }
 

}
almost 4 years ago · Santiago Trujillo 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!