0

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.

Kevin Workman
  • 41,537
  • 9
  • 68
  • 107
Ty Underwood
  • 897
  • 1
  • 6
  • 9
  • May I ask the value of roboDelayA? – Lain Feb 25 '14 at 14:30
  • roboDelayA and roboDelay are both currently set to 1, but it has been 1-500 for different movement durations. – Ty Underwood Feb 25 '14 at 14:31
  • Could the problem be that you have delay set to such a low number? Delay is by default in mili seconds, 1 milisecond delay between press and release might be causing the error? – Lain Feb 25 '14 at 14:38
  • the problem definitely persists regardless of the value I use, whatever value between 1 and 500, thanks though – Ty Underwood Feb 25 '14 at 15:04
  • Even 500 MS is only half a second. What happens if you try an even higher number? If you want better help, I suggest posting an [MCVE](http://stackoverflow.com/help/mcve) that we can copy and paste into our own Processing IDE. – Kevin Workman Feb 25 '14 at 19:54

0 Answers0