Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

290
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda