| Author |
Java Robots problem
|
Himanshu Rawat
Ranch Hand
Joined: Nov 27, 2005
Posts: 141
|
|
hi guys,
hope this is the right forum to ask this Q.
I made a simple java robot program, which opens a notepad and writes. After that its supposed to exit.
Although exit is not working but once i close this program, keys are working in arbitrary manner. for e.g. on pressing e, it clicks on tabs etc. I also need to reboot OS to get keys normal behavior back.
the code is:
public class RobotExp {
public static void main(String[] args) throws IOException {
try {
Robot robot = new Robot();
// Creates the delay of 5 sec so that you can open notepad before
// Robot start writting
// Runtime.getRuntime().exec("C:\\Program Files\\Internet Explorer\\iexplore.exe \"http://www.google.com\"");
Runtime.getRuntime().exec("notepad");
robot.delay(5000);
// robot.keyPress(KeyEvent.VK_CONTROL);
//robot.keyPress(KeyEvent.VK_T);
robot.keyPress(KeyEvent.VK_H);
robot.keyPress(KeyEvent.VK_I);
robot.keyPress(KeyEvent.VK_SPACE);
robot.keyPress(KeyEvent.VK_C);
robot.keyPress(KeyEvent.VK_H);
robot.keyPress(KeyEvent.VK_O);
robot.keyPress(KeyEvent.VK_D);
robot.keyPress(KeyEvent.VK_A);
robot.keyPress(KeyEvent.VK_N);
robot.keyPress(KeyEvent.VK_ENTER);
robot.delay(5000);
robot.keyPress(KeyEvent.VK_ALT);
robot.keyPress(KeyEvent.VK_F4);
// Don't save
robot.keyPress(KeyEvent.VK_TAB);
robot.keyRelease(KeyEvent.VK_TAB);
robot.delay(500);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
robot.delay(500);
} catch (AWTException e) {
e.printStackTrace();
}
}
}
Please tell me how to solve this problem?
|
rawat
SCJP 1.4
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32694
|
|
|
Don't know, but it seems odd that you are calling an exec() method without clearing the two associated streams. Google for "when Runtime.exec() won't" and read Michael Daconta's article before doing anything else.
|
 |
Himanshu Rawat
Ranch Hand
Joined: Nov 27, 2005
Posts: 141
|
|
solved . and even closing of notepad working fine too
thanks Campbell
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32694
|
|
You're welcome
How did you solve it? Did you use Daconta's hints?
|
 |
Himanshu Rawat
Ranch Hand
Joined: Nov 27, 2005
Posts: 141
|
|
hey Campbell,
I forgot to post the solution.sorry for that.
I killed the process in the end and for closing notepad i was pressing Alt F4, i wasn't releasing them in the end so i released them.
robot.keyRelease(KeyEvent.VK_ALT);
robot.keyRelease(KeyEvent.VK_F4);
i guess killing process was important . Silly mistakes
Before using Daconta's hints, i wanted to try myself and it worked before that. anyways i will still look into the hints
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
Himanshu Rawat wrote:Before using Daconta's hints, i wanted to try myself and it worked before that.
Then you got a bit lucky. I had quite a big application once that had one annoying bug - a conversion process would sometimes hang. I had no idea why. Then I read that article, applied it to the application, and the bug was gone.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
 |
|
|
subject: Java Robots problem
|
|
|