KeyPressed() Eventually Stops Working..?

edited July 17 in Questions about Code

I am creating a program where the player moves a character using keyPressed(). It works fine for the first few key presses, but eventually keyPressed() stops getting called. Any insights?

Boolean keys[] = {false, false, false, false,};

//draw is already being ran

void keyPressed() {
  println("key down");
  if(key == 'w') {
    keys[0] = true;
  }
  if(key == 's') {
    keys[1] = true;
  }
  if(key == 'a') {
    keys[2] = true;
  }
  if(key == 'd') {
    keys[3] = true;
  }
}

void keyReleased() {
  println("key up");
  if(key == 'w') {
    keys[0] = false;
  }
  if(key == 's') {
    keys[1] = false;
  }
  if(key == 'a') {
    keys[2] = false;
  }
  if(key == 'd') {
    keys[3] = false;
  }
}

Answers

Sign In or Register to comment.