If I press a key like shift, alt, caps lock, etc. the sketch crashes. How do I make this stop happening? Thanks for reading this here’s the code:
float v = 5;
int x = 1920/2;
int y = 1080/2;
boolean [] keys = new boolean[128];
import java.awt.Robot;
Robot robot;
void setup () {
size(600, 600);
try {
robot = new Robot();
}
catch (Throwable e) {
}
}
void draw() {
if (keyPressed) {
if (keys['w']) {
y -= v;
}
if (keys['a']) {
x -= v;
}
if (keys['s']) {
y += v;
}
if (keys['d']) {
x += v;
}
}
robot.mouseMove(x, y);
}
void keyPressed() {
keys[key] = true;
}
void keyReleased() {
keys[key] = false;
}