tags:

views:

73

answers:

1

hi.... i m doing the project on remote screen capturing and controlling.... i have done the screen capturing.... now i watn to make controlling....in it i want.... i have done the controlling through mouse events like mouseMove & mousePressed,mouseReleased... but the controlling by Keyboard is not done...so tell me how to do KeyBoard events on robot class and using it how to make controlling...?

so suggest me the solution for how to make controlling by keyboard event.... thanks...

+1  A: 

The Robot class has both keyPress and keyRelease method which can be used to cause key events on a machine.

The following is a little demonstration code that I tried out that launches Notepad in Windows, waits half a second and types hello into it:

Runtime.getRuntime().exec("notepad");

Robot r = new Robot();
r.setAutoDelay(100);
r.delay(500);
r.keyPress(KeyEvent.VK_H);
r.keyPress(KeyEvent.VK_E);
r.keyPress(KeyEvent.VK_L);
r.keyPress(KeyEvent.VK_L);
r.keyPress(KeyEvent.VK_O);
coobird
Am I the only one who thinks the interface to the Robot class looks really bad?
Crippledsmurf
True, it doesn't look very elegant.
coobird
I concur - it needs improvement.
javamonkey79