# Preventing Keypress from continuously activating

**URL:** <https://discourse.processing.org/t/preventing-keypress-from-continuously-activating/16241>\
**Category:** Coding Questions\
**Created:** [December 8, 2019, 5:14am UTC](https://discourse.processing.org/t/preventing-keypress-from-continuously-activating/16241 "2019-12-08T05:14:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kitty](https://avatars.discourse-cdn.com/v4/letter/k/278dde/32.png) [@Kitty](https://discourse.processing.org/u/Kitty)\
**Post date:** [December 8, 2019, 5:14am UTC](https://discourse.processing.org/t/preventing-keypress-from-continuously-activating/16241/1 "2019-12-08T05:14:18Z")

</div>

I have my code for keypress here. What I’m looking for is a way to prevent the code from jumping straight from “isGameStart” to “isGameS1”. So that it requires you to hit the ENTER key again.

```auto
void keyReleased()
{
if (keyCode == ENTER && isGameStart)
    {
    isGameStart = false;
    isInstructions = true;
    }
if (keyCode == ENTER && isInstructions)
    {
    isInstructions = false;
    isGameS1 = true;
    }
}

```

---

<div class="post-metadata">

**Author:** ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)\
**Post date:** [December 8, 2019, 5:23am UTC](https://discourse.processing.org/t/preventing-keypress-from-continuously-activating/16241/2 "2019-12-08T05:23:43Z")

</div>

I assume isGameS1 is actually isInstructions, right? In any case, you need to use if else, not just if.

How if Else works :

```auto
//this happens all during one frame!
if (true) {//this is executed}

if (true) {
   //this is executed
} else { //this is not}

if (false) {
   //this is not
} else if (false) {
   //this is not
} else if (false) {
   //this is not
} else { //this is executed}

if (false) {
   //this is not
} else if (true) {
   //this is executed
} else if (true) { //this is not even checked, since we already found a true condition before
   //this is not!!!
}

```

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [December 8, 2019, 5:24am UTC](https://discourse.processing.org/t/preventing-keypress-from-continuously-activating/16241/3 "2019-12-08T05:24:10Z")

</div>

might be possible using just a other sort order of the commands,  
but a other logic might also help

```auto
void keyReleased() {
  if (keyCode == ENTER ) {
    if (isInstructions) {
      isInstructions = false;
      isGameS1 = true;
    }
    if (isGameStart) {
      isGameStart = false;
      isInstructions = true;
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [December 8, 2019, 8:56pm UTC](https://discourse.processing.org/t/preventing-keypress-from-continuously-activating/16241/4 "2019-12-08T20:56:10Z")

</div>

I prefer the if-else here. If you were to re-arrange the code in the future, this bug will return. When you read the code, you should see the connection and dependency.

Kf
