User Input from KeyBoard

I am trying to write a code that will return a string as a result of the user pressing 1, 2, or 3 on their keyboard. This is what I have so far but when i press keys nothing happens. What is wrong with my code?

String choice;
boolean pressed = false;

void setup ()
{
  size (2000, 2000);
  fill (0);
}

void getTable()
{
  choice = getChoice();
  println(choice);
}

void keyPressed()
{
    
    if (key==1)
    choice = "car_status_BMW_323i.csv";
    if (key==2)
    choice = "car_status_Truck_F150.csv";
    if (key==3);
    choice = "exit";
    
    pressed = true;
  
}

String getChoice()
{
  do
  {
    text("make choice 1, 2, 3", 1000, 1000);
  }while (pressed == false);
  
  return choice;

}
1 Like

Sounds like you need to do some debugging. Print out the value of key to understand how its value works. You also might want to consult the reference.

1 Like