简体   繁体   English

Java - 获取活动窗口的标题

[英]Java - Get title of active window

I need to get title of current active window(for example right now: Google Chrome).我需要获取当前活动窗口的标题(例如现在:Google Chrome)。 I search smth in internet, and found only this javax.swing.FocusManager.getCurrentManager().getActiveWindow();我在互联网上搜索,只找到了这个javax.swing.FocusManager.getCurrentManager().getActiveWindow(); . . But i don't know how to get PROGRAM TITLE with that code.但我不知道如何使用该代码获得程序标题。

If you are fine with a non-java solution that will work for Windows computers, there is a programming language called AutoHotkey (AHK) that is more suited for this kind of task.如果您对适用于 Windows 计算机的非 Java 解决方案感到满意,则有一种称为 AutoHotkey (AHK) 的编程语言更适合此类任务。 There exists a popular script called "Window Spy" (also known as "ActiveWindowInfo") that has the ability to view the title of the active window, as well as other information such as PID, the name of the .exe that the Window is an instance of, and etc. (I have attached a screenshot of what Window Spy told about the Google Chrome window I was using to write this reply. In the screenshot, I have also indicated which part of it tells you the Title of the Window).存在一个名为“Window Spy”(也称为“ActiveWindowInfo”)的流行脚本,它能够查看活动窗口的标题,以及其他信息,例如 PID、窗口所在的 .exe 的名称等的一个实例(我附上了 Window Spy 告诉我的关于 Google Chrome 窗口我用来写这个回复的截图。在截图中,我还指出了它的哪一部分告诉你窗口的标题)。 窗口间谍的屏幕截图

This script comes with most AutoHotkey IDEs (such as SciTe4Autohotkey if you are interested).该脚本随大多数 AutoHotkey IDE 一起提供(如果您感兴趣,例如 SciTe4Autohotkey)。 However, you can perfectly well run the script without an IDE.但是,您可以在没有 IDE 的情况下完美地运行脚本。

Here are some quickstart instructions:以下是一些快速入门说明:

  1. First, you will need to install AHK itself (here is the official website )首先,你需要自己安装AHK(这里是官网
  2. You can download the script itself by navigating to https://raw.githubusercontent.com/fincs/SciTE4AutoHotkey/master/source/tools/ActiveWindowInfo.ahk in Chrome, using the shortcut Control+S to save the script to your computer.您可以通过在 Chrome 中导航到https://raw.githubusercontent.com/fincs/SciTE4AutoHotkey/master/source/tools/ActiveWindowInfo.ahk来下载脚本本身,使用快捷键 Control+S 将脚本保存到您的计算机。 Make sure that when you download the script, it ends with a .ahk instead of the .txt that it will default to .确保下载脚本时,它以 .ahk 结尾,而不是默认为 .txt 的 .txt
  3. Navigate to the file that you downloaded and run it with AutoHotkey (It should be the default thing that happens if you double click the .ahk file with AutoHotkey installed).导航到您下载的文件并使用 AutoHotkey 运行它(如果您双击安装了 AutoHotkey 的 .ahk 文件,这应该是默认情况)。

If you need any more info on how to use the script, please let me know.如果您需要有关如何使用脚本的更多信息,请告诉我。

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

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