简体   繁体   English

按标题查找窗口并以Java引入前景

[英]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. 找到最佳解决方案后,我想模拟一系列按键(使用awt.Robot)来解决游戏。

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 project. 我正在使用Linux,可以简单地使用一些CLI工具,因为这不是我项目的主要重点。

I found a tool called wmctrl which does excatly this. 我找到了一个名为wmctrl的工具,它确实可以做到这一点。 I simply start it using ProcessBuilder. 我只是使用ProcessBuilder启动它。

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

To answer part of your question, see xprop or xwininfo to find the window. 要回答部分问题,请参见xpropxwininfo查找窗口。

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. 对于第二部分,尽管Xlib提供了执行此操作的功能( XRaiseWindow() ),但我不知道如何从命令行或Java内部执行此操作。 See this thread though. 看到这个线程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM