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

295
Views
¿Puedo hacer una función que devuelva un número entero en función de la tecla presionada (nodejs)?

Estoy usando nodejs y solo necesito una función que cuando llamo devuelva el valor de la tecla presionada (0 si no se presiona ninguna tecla).

Intenté usar ioHook pero solo ejecuta una función cada vez que se presiona una tecla.

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

0

Así es como lo haría en js simple Esto no está en el nodo js, pero el código debería verse igual solo que con un nombre de detector de eventos diferente, así que decidí publicar esto y puede ayudarlo a simularlo en el 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) })

y devuelve una Promesa , por lo que, para un ejemplo simple, se puede usar como se muestra a continuación:

 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!