I need to get title of current active window(for example right now: Google Chrome). I search smth in internet, and found only this javax.swing.FocusManager.getCurrentManager().getActiveWindow();
. But i don't know how to get PROGRAM TITLE with that code.
-
Are you looking for the current active window within this same java app or outside the app? Because if you are trying to get the title of google chrome I understand you will end up with null from here https://stackoverflow.com/questions/34992027/how-to-get-current-active-window-while-running-my-java-application. – Omar Abdel Bari Oct 10 '20 at 19:32
-
@OmarAbdelBari yes, but how to get title? – CatchThels Oct 10 '20 at 19:34
-
I just wanted to point out that if it's not a window within your app then you would not be able to get it with the code you posted above (based on the link). I don't see any method for receiving the title in https://docs.oracle.com/javase/10/docs/api/java/awt/Window.html. If the windows are within your app, why not just set the window name to something you can work with and then use *getName()* instead? – Omar Abdel Bari Oct 10 '20 at 19:59
1 Answers
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. 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).
This script comes with most AutoHotkey IDEs (such as SciTe4Autohotkey if you are interested). However, you can perfectly well run the script without an IDE.
Here are some quickstart instructions:
- First, you will need to install AHK itself (here is the official website)
- 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. Make sure that when you download the script, it ends with a .ahk instead of the .txt that it will default to.
- 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).
If you need any more info on how to use the script, please let me know.

- 2,234
- 1
- 4
- 24
-
If this is a good answer, please mark it as such. If it is not, *please tell me what I can do to improve it* – Spyre Oct 11 '20 at 15:11