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

123
Vistas
P5js I want code to run for a sustained amount of time after keyIsPressed

I am a complete beginner and I am working inside a custom p5js framework for a school project. We are working on a clock.

Basically, I want a piece of code to stay active for ~5 seconds after using the keyIsPressed feature. I've tried just about every solution I can possibly think of, for loops, while loops. Even my teacher hasn't been able to help me solve this.

The kicker is we are not allowed to use the native p5js seconds. Since we are working inside the clock framework for school they have made custom hour, minute, second objects. I feel like these will be the key but I just can figure it out.

 if((keyIsPressed === true) &&  (keyCode === ENTER)) {
  let timer = obj.seconds;

    if(timer < (obj.seconds + 10)){
      fill(255, 0, 0);
      ellipse(700, 250, 300, 300);
    } else {
      fill(0);
      ellipse(700, 250, 300, 300);
    }
  }

Is there a way where I can sustain the code inside this if statement instead of it just running while the key is held?

This is probably a silly question but I just couldn't find an answer anywhere, Thank you in advance.

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