How do I draw a line when the mouse is pressed, and then have that line change type when the mouse and a certain key are pressed at the same time?

For example, I would like to have a “normal” line drawn when only the mouse is pressed, but have that line change color and/or size when the mouse and a certain key are pressed at the same time.

Here I just change the color every time you press the space key. You can adapt the class to keep track of width or some other factor of your line.

Kf

//===========================================================================
// GLOBAL VARIABLES:
ArrayList<ColorPoint> points;
color currColor=150;  //Some sort of grey

//===========================================================================
// PROCESSING DEFAULT FUNCTIONS:

void settings() {
  size(400, 600);
}

void setup() {

  textAlign(CENTER, CENTER);
  rectMode(CENTER);

  fill(255);
  strokeWeight(2);

  points=new ArrayList<ColorPoint>();
}

void draw() {
  background(0);
  
  fill(250);
  text("Mouse pressed and drag to draw points, space to change color", width/2,10);
  
  for(int i=0;i<points.size()-1;i++){
    ColorPoint p1 = points.get(i);
    ColorPoint p2 = points.get(i+1);
    
    //Draw lines from this point to point+1
    stroke(p1.colorPoint);
    line(p1.point.x,p1.point.y,p2.point.x,p2.point.y);
  }
}

void keyReleased() {
  
  if(key==' '){
    int newRed=int(random(256));
    int newGreen=int(random(256));
    int newBlue=int(random(256));
    currColor=color(newRed, newGreen, newBlue);
  }
}

void mouseDragged() {
  points.add(new ColorPoint(mouseX, mouseY, currColor));
}


//===========================================================================
// OTHER FUNCTIONS:
class ColorPoint {
  color colorPoint;  
  PVector point;
  ColorPoint(float x, float y, color c){
    colorPoint=c;
    point=new PVector(x,y);
  }
}