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

288
Views
Can i make a function that returns an integer based on the key pressed (nodejs)

I'm using nodejs and i just need a function that when i call returns the value of the key pressed (0 if no key pressed).

I have tried using ioHook but that just executes a function whenever a key is pressed.

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

0

This is how I would do it on simple js This is not on node js but the code should look like the same only with a different event listener name so I decided to post this and it may help you simulate it on backend

const getCurrentKey = () => new Promise((resolve , reject) =>{

  function handleKeyDown(event){
      resolve(event);
      document.removeEventListener('keydown' , handleKeyDown) // removing the event listener so it'll not be triggered along with others next time
  }

  document.addEventListener('keydown' , handleKeyDown)

})

and it returns a Promise so for a simple example it can be used like below:

async function test(){
  const e = await getCurrentKey();
}
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!