Inside the draw function i made a keyPressed. I want that piece of code to run only if i press r, but for some reason it is not working. Is there a better way to do it. I also want to put multiple different keys to run different part of the code( not included in the below code). What is the best way to do it. Please help
if (keyPressed) {
if (key=='r') {
shape(baseMap, 10, 10, width, height);
for (int i=1; i<intConfirmedCases.size(); i++) {
fill(#F21642);
int x=intX.get(i); //random value of x position
int y= intY.get(i); //random value of y position
ellipse(x, y, 30, 30);
//If condition was used to align the text inside the ellipse. For value of x is changed bases the the number of digits in the confirmed case value so that the text is perfectly inside the ellipse
if (intConfirmedCases.get(i)<10) {
fill(#0D0C0C);
text(intConfirmedCases.get(i), x-3, y+2);
} //Confirmedcases is printed insde the ellipse
if (intConfirmedCases.get(i)<100&&intConfirmedCases.get(i)>=10) {
fill(#0D0C0C);
text(intConfirmedCases.get(i), x-7, y+2);
}
if (intConfirmedCases.get(i)>99) {
fill(#0D0C0C);
text(intConfirmedCases.get(i), x-10, y+2);
}
if (strDistrict.get(i).equals("parsa")||
strDistrict.get(i).equals("bara")||
strDistrict.get(i).equals("rautahat")||
strDistrict.get(i).equals("sarlahi")||
strDistrict.get(i).equals("mahottari")||
strDistrict.get(i).equals("dhanusha")) {
pushMatrix();
textSize(10);
fill(#070808);
//translate(x+15,y+10);
//rotate(PI/4);
text(strDistrict.get(i), x-15, y+30);
popMatrix();
} else {
textSize(10);
fill(#373739);
text(strDistrict.get(i), x+15, y+10);
}
text("Index", 30, height-130);
fill(#F21642);
ellipse(40, height-100, 30, 30);
fill(#0E0F0E);
text("--> Confirmed Corona Cases", 70, height-97);
}
}
}
}