开发者

Find window by title and bring in the foreground in Java

I'm currently working on a project for my studies. I'm trying to solve a simple puzzle game by using breadth first search. After I have found the optimal solution I want to simulate a series of keypresses (using awt.Robot) to solve the game.

Is there a way to bring a window with known title to the foreground. I'm using Linux and it would be okay to simply use some CLI tools since this is not the main focus of my proje开发者_高级运维ct.


I found a tool called wmctrl which does excatly this. I simply start it using ProcessBuilder.

new ProcessBuilder("wmctrl",  "-a", title).start()


To answer part of your question, see xprop or xwininfo to find the window.

For the second part, while Xlib provides a function to do this (XRaiseWindow()), I don't know how to do from the command line or inside Java. See this thread though.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜