Saturday, April 30, 2011

Processing and Arrow keys

Although in the Processing API it is mentioned that key returns the value of the pressed key, but when it comes to arrows it just returns question mark !!! The magic is to use keyCode :-)

void keyPressed(){
  //print(keyCode);
  if (keyCode == RIGHT){
    //GO RIGHT
  }
  else if (keyCode == LEFT){
    //GO LEFT
  }

  else if (keyCode == UP){
    //GO UP
  }
  else if (keyCode == DOWN){
    //GO DOWN
  }


}//end of keyPressed