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

125
Visualizações
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 à 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