Java robot class – add focus to a specific running application?

I just want to find out if / how to let the Java robot class change the focus from a running Java application to a specific process, such as MS word or Firefox

thank you!

Solution

The robot cannot do it automatically You can activate another application through alt tab as suggested above, but you need to know the Z order of the applications to be activated I think to really do your best, you need to get the window handle (hWnd) of the top-level window to activate (if this is a Windows application), and then activate the desired window using the windows user32 library function To this end, I recommend using JNA as one of the simplest methods (compared with JNI) You must first download JNA Jar and platform Jar files and put them on the classpath, and then you can easily call most OS methods For example, I have started and run something like this for a Windows application. I can get the hWnd of the running top-level windows application according to the window name (complete or partial), and then use the hWnd to call the setforeroundwindow function of user32 If you want to activate Windows applications and want to pursue further, please answer this question and I can show you my code If so, you will need to know in detail what you are trying to do

Good luck!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>