In Processing I am using a Java Robot
class in my processing script to press keys for a game. In whatever way I use it, the key press flashes and pulses unsteadily for whatever duration I've told it to press, thus pressing A in an emulated game four or five times in a flash. How can I fix this? I am using the Robot
class like this:
void robotPress() {
roboReady = false;
if (keyPress == 1){
robot.keyPress(KeyEvent.VK_A);
robot.delay(roboDelayA);
robot.keyRelease(KeyEvent.VK_A);
}else if (keyPress == 2){
//b
robot.keyPress(KeyEvent.VK_B);
robot.delay(roboDelayA);
robot.keyRelease(KeyEvent.VK_B);
}else if (keyPress == 3){
//x
robot.keyPress(89);
robot.delay(roboDelayA);
robot.keyRelease(89);
}else if (keyPress == 4){
//y
robot.keyPress(91);
robot.delay(roboDelayA);
robot.keyRelease(91);
}else if (keyPress == 5){
//l
robot.keyPress(67);
robot.delay(roboDelayA);
robot.keyRelease(67);
}else if (keyPress == 6){
//r
robot.keyPress(82);
robot.delay(roboDelayA);
robot.keyRelease(82);
}else if (keyPress == 7){
//start
robot.keyPress(81);
robot.delay(roboDelayA);
robot.keyRelease(81);
}else if (keyPress == 8){
//select
robot.keyPress(86);
robot.delay(roboDelayA);
robot.keyRelease(86);
}else if (keyPress == 9){
//up
robot.keyPress(38);
robot.delay(roboDelay);
robot.keyRelease(38);
}else if (keyPress == 10){
//down
robot.keyPress(40);
robot.delay(roboDelay);
robot.keyRelease(40);
}else if (keyPress == 11){
//left
robot.keyPress(37);
robot.delay(roboDelay);
robot.keyRelease(37);
}else if (keyPress == 12){
//right
robot.keyPress(39);
robot.delay(roboDelay);
robot.keyRelease(39);
}
keyPress = 0;
roboReady = true;
}
the variable keyPress
is the code its looking for for which button to be pressing. All the buttons press and release correctly. I am using thread("robotPress");
to call this function in a different thread, it makes no difference than if it's in void draw()
; for the performance. There are no errors of any kind, and all my fiddling doesn't change anything. I need it to be a brief single pulse for most buttons, but be held for a brief duration for directional data. Any ideas?
EDIT: You may comment on the numerical data for the keys vs VK_A etc, I had to import a dependency differently to get keyEvent.VK_A to not give an 'ambiguous' error, so I am changing those over. It does not affect the problem I am having in any way.