Help with mousePressed or keyPressed

Hello guys,
I need help to make this code into mouse pressed or keypressed so I want that the code appears only if I press the mouse or a key as you want but if someone could help me it would be amazing !

class bug {
  float x = random(width);
  float y = random(-200,-100);
  float speedY = random(4,10);
  float taille = random (50, 70);
  void fall() {
    y = y+speedY;
    
    if (y > height) {
      y = random (-200,-100);
    }
  }
  
  void show() {
    fill(0);
    line(x,y,x,y+taille);
  }
  }
bug[] bugs = new bug[2000];
void setup() {
  fullScreen();
  for (int i = 0; i < bugs.length; i++) {
    bugs[i] = new bug();
  }
}
void draw() {  
  for (int i = 0; i < bugs.length; i++) {
    bugs[i].fall();
    bugs[i].show();
  }
}

set a global variable isRunning to false

in keyPressed set it to true

in draw add


void draw() {
if(isRunning) {
....
}
}

Explore the references:

Think about the flow:
Press a key or mouse and set a variable
Make a decision base on that variable

:)

thank you guys it helped me alot ^^

2 Likes