How to handle a GUI of an external software from w

2019-08-12 08:03发布

I need to run an external application from within my Java code. I can run the application with Runtime r = Runtime.getRuntime() and then r.exec(...), however, this brings up the GUI of the application. And I still need enter some settings in some fields and press enter. So:

Is there some way to handle a GUI (filling out fields, pressing "return"..etc) from within Java code?

Thanks in advance for any answers,

Anas

2条回答
Animai°情兽
2楼-- · 2019-08-12 08:35

Use the AWT Robot class:

"This class is used to generate native system input events for the purposes of test automation, self-running demos, and other applications where control of the mouse and keyboard is needed."

查看更多
乱世女痞
3楼-- · 2019-08-12 08:39

Thanks RichieHindle and Vanya for your comments. AWT Robot class does work with an external softwatre (in this instance, I only need to press an enter. It did that, no problem). But further handling seems quite difficult, since every key stroke (entering a username) needs a java line (unless there is someshort cut that I missed). I will try to automata the process more, or find some work around.

Thank you, this was informative.

Anas

查看更多
登录 后发表回答