Making a keyPressed do a launch and launch sequence?

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

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

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.
    }
  }
}

assuming your key is a




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++;
  }
}
//