tags:

views:

213

answers:

3

hi there is a problem during handling Robot.KeyPress(KeyEvent...) is it neccesarry to specify all the keys every time.... e.g Robot.KeyPress(KeyEvent.VK_A); Robot.KeyPress(KeyEvent.VK_B); Robot.KeyPress(KeyEvent.VK_C); if there is any shortkut for not repeating this everytime...plz tell me.....

and the interpretation for keys that are recieved at client side is diff...than that is sent from server side...

so please help me...

+1  A: 

There is no method that accepts simultaneous key presses from a large number of keys since most keyboards have a limit on the maximum number of pressed keys at a given time, and there is rarely a reason to simultaneously press more than three keys at once.

If you have a specific sequence of keys you want to send repeatedly, you can put it in an array and iterate through it:

     int[] events = {KeyEvent.VK_A, KeyEvent.VK_B, KeyEvent.VK_C};
 Robot robot;
 try {
  robot = new Robot();
  for (int i = 0; i < events.length; i++) {
   robot.keyPress(events[i]);
   robot.keyRelease(events[i]);
  }
 } catch (AWTException e) {
  e.printStackTrace();
 }

Or you can put it in a function instead.

As for the interpretation for keys, I'm guessing you are forgetting the keyRelease() call, if not, can you post exactly what you are receiving on the client/server side?

yx
This would be a good place to use a for-each loop:for (int key : events) { ...}
James
A: 

I wrote a high-level, convenient API for using the AWT Robot. Have a look at the Gestures API in the Window Licker library.

It addresses the issue that key events are interpreted as different symbols in different locales, but only by using configuration files to describe keyboard layouts. I've not found a way to do this automatically just by using the Java APIs.

Nat
A: 

You might want to take a look at this SmartRobot class that implements exactly what you need

Demiurg