Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

128
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!