How do i detect when spacebar is pressed?

this works:



boolean check = false; 

void draw() {
  if (check) {
    println("1");
  }
}

void keyPressed() {
  //i'd like to detect when space bar is pressed.

  if (key==' ') {

    check = true;
    //
  }//if
  //
}//func