# Making a keyPressed do a launch and launch sequence?

**URL:** https://discourse.processing.org/t/making-a-keypressed-do-a-launch-and-launch-sequence/30077
**Category:** Coding Questions
**Created:** [May 13, 2021, 4:02am UTC](https://discourse.processing.org/t/making-a-keypressed-do-a-launch-and-launch-sequence/30077 "2021-05-13T04:02:53Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![yagirl\_belle](https://avatars.discourse-cdn.com/v4/letter/y/d07c76/32.png) [@yagirl\_belle](https://discourse.processing.org/u/yagirl_belle)
#### Post date: [May 13, 2021, 4:02am UTC](https://discourse.processing.org/t/making-a-keypressed-do-a-launch-and-launch-sequence/30077/1 "2021-05-13T04:02:53Z")

</div>

Hey everyone,

I’m trying to do a launch sequence by pressing the same key twice. 1st press = start launch, 2nd press = launch object

I’m not certain how to do this and what I need to use. I’m using booleans to run the start launch and launch sequence but I don’t know how to get processing to tell the diffference between the first key press and the second key press

Yes I have looked at references

---

<div class="post-metadata">

### Author: ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)
#### Post date: [May 13, 2021, 5:40am UTC](https://discourse.processing.org/t/making-a-keypressed-do-a-launch-and-launch-sequence/30077/2 "2021-05-13T05:40:13Z")

</div>

You can use those same booleans to check if a keypress is the first or second press.

```auto
boolean b_any_press = false;
boolean b_launch = false;
int i_saved_key=-1;
void keyPressed(){
  if( !b_any_press ){ // No press has been done yet.
    i_saved_key = key;
    b_any_press = true;
  } else { // We've seen one press at least.
    if( i_saved_key == key ){ // Same second press detected?
      b_launch = true; // Yep! Launch!
    } else {
      i_saved_key = key; // Not the same key pressed again. Store new "first" press.
    }
  }
}

```

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [May 14, 2021, 2:48pm UTC](https://discourse.processing.org/t/making-a-keypressed-do-a-launch-and-launch-sequence/30077/3 "2021-05-14T14:48:03Z")

</div>

assuming your key is a

```auto

int count=0; 

void setup() {
  size(700, 700);
  background(100);
}

void draw() {
  background(100); 
  switch(count) {
  case 0: 
    // No press has been done yet.
    text("wait", 44, 44); 
    break; 

  case 1:
    // We've seen one press
    // start launch
    text("start launch", 44, 44);
    break; 

  case 2: 
    // launch object
    text("launch object", 44, 44);
    break;

  default: 
    count=0;
    break;
  }//switch
  //
}//func 

void keyPressed() {
  if (key=='a') {
    count++;
  }
}
//

```
