0

I am trying to launch a chrome browser, select all then copy. the copy command (CTRL+C) seems to kill the console when running the jar file through a bat file.

public void sendKeys(key1, key2){
Robot robot=new Robot();
robot.keyPress(key1)
robot.keyPress(key2)
robot.keyrelease(key1)
robot.keyrelease(key2)

}  

public void launchBrowser(){

launchBrowser();// launches browser using selenium
sendKeys("CTRL","A"); // Performs select All, works fine
sendKeys("CTRL","C"); // Copy the selected content to clipboard.
   // CTRL+C works when i am in IDE, however if I run my jar file with console, CTRL+C kills the console.
}

I have tried to minimize the console which is running the program to make sure that it is in focus, but it doesn't seem to work.

I have also tried to run my program with javaw.exe instead of java so it will not give me a console, however that doesn't work either.

PS: The same code works on IDE flawlessly, as in when I run through eclipse. However when I deploy jars, it doesnt.

Bounty Collector
  • 615
  • 7
  • 19
  • https://stackoverflow.com/questions/1216172/how-can-i-intercept-ctrlc-in-a-cli-application – rostegg Aug 06 '20 at 06:41
  • whether you minimize the console or not, it still sends sigint (https://en.wikipedia.org/wiki/Signal_(IPC)) – rostegg Aug 06 '20 at 06:43
  • and your way to copy it's not better way to do this, you should search by tag and then get value of searched element – rostegg Aug 06 '20 at 06:45
  • yeah, forgot about this (https://docs.oracle.com/javase/7/docs/api/java/awt/Toolkit.html#getSystemClipboard()), so you can easy set your values to clipboard – rostegg Aug 06 '20 at 06:51

0 Answers0