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

129
Vistas
JS how to have keyDown for a limited amount of time

I'm trying to make a video game with Javascript, HTML and css, a platformer. But I encountered a difficulty with the eternal jump on 'w', I have a "gravity that get me down if I don't do anything. So I thought it was possible to get:

function up() {
  document.addEventListener("keydown", function (event) {
      if (event.key === "w" || event.key === "ArrowUp") {
          upKey = true;

but it must work only for x seconds so it's a limited jump, any ideas are welcomed. I tried with principe:

function execOnce(fn, context) {
  var result;
  return function () {
    if (fn) {
      result = fn.apply(context || this, arguments);
      fn = null;
    }
    return result;
  };
}

function sayHello() {
  console.log("hello world");
}

var helloOnce = execOnce(sayHello);

helloOnce(); // hello world
helloOnce(); // nothing but emptiness
helloOnce();
helloOnce();

But my variables are true and not a number so I don't know how to do. Thank you (yes I'm new to JS)

about 4 years ago · Juan Pablo Isaza
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