Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

289
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda