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

195
Views
JavaScript keydown event is not triggering with setTimeout

I want to automatically trigger a keydown event after specific amount of time has passed. I set up a timout event for this with the code below:

setTimeout(
    function() {
        document.querySelector("body").dispatchEvent(new KeyboardEvent('keydown', {
            keyCode: 83,
            altKey: true
        }));
    },
    12000
);

However, it doesn't seem to trigger anything. Could anyone please help me in figuring out how can i send a keydown event in such cases?

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

0

I just tried your code and it triggers alright:

document.querySelector("body").addEventListener('keydown', (e) => {
  console.log('triggered', e)
})

setTimeout(
    function() {
      document.querySelector("body").dispatchEvent(new KeyboardEvent('keydown', {
        keyCode: 83,
        altKey: true
      }));
    },
    2000
);

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!