• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java Robots problem

 
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Marshal
Posts: 79254
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
solved . and even closing of notepad working fine too

thanks Campbell
 
Campbell Ritchie
Marshal
Posts: 79254
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome

How did you solve it? Did you use Daconta's hints?
 
Himanshu Rawat
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
I RELEASE YOU! (for now .... ) Feel free to peruse this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic