Keyboard
key is a variable that tells you which key is being pressed. Note that the if statement uses just single quotes around each letter, not double quotes. A single character is a char data type, rather than a whole String, and uses single quotes instead of double quotes.
PImage keyboard;
PImage tap;
PImage hit;
PImage hit2;
PImage hit3;
PImage hit4;
PImage hammer;
PImage hammer2;
void setup()
{
size(1024,768);
keyboard=loadImage("keyboard.jpg");
tap=loadImage("key1.jpg");
hit=loadImage("key2.jpg");
hit2=loadImage("key3.jpg");
hit3=loadImage("key4.jpg");
hit4=loadImage("key5.jpg");
hammer=loadImage("key6.jpg");
hammer2=loadImage("key7.jpg") ;
}
void draw ()
{
if (keyPressed)
{
if (key == 'j')
{
image(hit,0,0);
}
else if (key == 'u')
{
image(hit2,0,0);
}
else if (key == 'n')
{
image(hit3,0,0);
}
else if (key == ' ')
{
image(hit4,0,0);
}
else if (key == 't')
{
image(hammer,0,0);
}
else if (key == 'g')
{
image(hammer2,0,0);
}
else
{
image(tap,0,0);
}
}
else
{
image(keyboard,0,0);
}
}