Hello!
I am trying to get keyPressed/keyReleased to work for several keys simultaneously. Every single stroke works and two at the same time too. But nerver for all four of them? Is there somthing with internal handling of key events that limits it to max three key? Here is my example code:
boolean upPressed = false;
boolean downPressed = false;
boolean leftPressed = false;
boolean rightPressed = false;
float circleX = 100;
float circleY = 100;
void setup(){
size(200,200);
}
void draw() {
background(200);
if (upPressed) {
ellipse(circleX, circleY-30, 20, 20);
}
if (downPressed) {
ellipse(circleX, circleY+30, 20, 20);
}
if (leftPressed) {
ellipse(circleX-30, circleY, 20, 20);
}
if (rightPressed) {
ellipse(circleX + 30, circleY, 20, 20);
}
}
void keyPressed() {
if (keyCode == UP) {
upPressed = true;
}
else if (keyCode == DOWN) {
downPressed = true;
}
else if (keyCode == LEFT) {
leftPressed = true;
}
else if (keyCode == RIGHT) {
rightPressed = true;
}
}
void keyReleased() {
if (keyCode == UP) {
upPressed = false;
}
else if (keyCode == DOWN) {
downPressed = false;
}
else if (keyCode == LEFT) {
leftPressed = false;
}
else if (keyCode == RIGHT) {
rightPressed = false;
}
}