# How can I restart the program with keypress

**URL:** <https://discourse.processing.org/t/how-can-i-restart-the-program-with-keypress/15446>\
**Category:** Coding Questions\
**Created:** [November 13, 2019, 4:59am UTC](https://discourse.processing.org/t/how-can-i-restart-the-program-with-keypress/15446 "2019-11-13T04:59:57Z")\
**Posts on this page:** 1\
**Showing post:** 27

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [November 22, 2019, 7:18pm UTC](https://discourse.processing.org/t/how-can-i-restart-the-program-with-keypress/15446/27 "2019-11-22T19:18:31Z")

</div>

One simple way of approaching restart-timing is to rerun your setup each time you restart, and maintain a global variable with the last time you restarted. This lets you compute either the total run time (millis) or the current runtime (restart-millis).

Processing always runs setup on frame 0 – so one way to rerun it (and reset frameCount at the same time) is to set the frameCount to -1.

```auto
/**
 * Restart Frame 0
 * 2019-11 Processing 3.4 
 * Press key to restart -- setup() runs again on the following frame.
 * Sketch demonstrates computing a custom millis based on last restart.
 */

int start;
color bgcolor;
int level = 0;

void setup() {
  start = millis();
  bgcolor = color(random(255), random(255), random(255));
  level = level + 1;
}

int reMillis() {
  return millis()-start;
}

void draw() {
  background(bgcolor);
  text(level, 20, 20);
  text(frameCount, 20, 40);
  text(reMillis(), 20, 60);
  text(millis(), 20, 85);
}

void keyReleased() {
  frameCount = -1;
}

```

Note that this behavior isn’t officially documented in the reference – but it has been a part of Processing for a very long time.

---

_[View the full topic](https://discourse.processing.org/t/how-can-i-restart-the-program-with-keypress/15446)._
