Automatically Detect WinTitle ?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Class1
Posts: 39
Joined: 28 Sep 2017, 02:51

Automatically Detect WinTitle ?

17 Dec 2017, 18:12

I'm trying make the script automatically detects the Window Title when a certain Process is running
Lets take Google Chrome for the sake of simplicity (correct me if I'm wrong)

Based on my understanding:
Process is the .exe application "chrome.exe"
Window Title is the title of the palette under task bar *lets say if I just opened up the chrome the Window Title is gonna be: "New Tab - Google Chrome" as shown below

Image
Image

My code:

Code: Select all

Process, Exist, chrome.exe ; checks if Program.exe is running
WinGetTitle, DetectedWindowName, ahk_exe ; detects the windows title of the Program.exe (e.g. "New Tab - Google Chrome")
IfWinActive, %DetectedWindowName% ; if the window is active
	MsgBox, The active window is "%DetectedWindowName%"
Any help is appreciated,
Class1
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Automatically Detect WinTitle ?

17 Dec 2017, 21:04

For sake of simplicity, I'm not going to install software to check your code. I read it and comment.

First line: AHK checks to see if chrome.exe is running and sets the Errorlevel accordingly. The code you posted ignores the result completely.
Second Line: wrong use of ahk_exe. AHK expects to see the WinTitle as parameter. Unlikely to have a window titled "ahk_exe", but when you do have that -> it works.
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Automatically Detect WinTitle ?

17 Dec 2017, 21:17

Try this:

Code: Select all

F12:: ; hotkey
Process, Exist, notepad.exe
If ErrorLevel {
    WinGetTitle, DetectedWindowName, ahk_pid %ErrorLevel%
	MsgBox, The detected window is "%DetectedWindowName%"
}
Return
I hope that helps.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: inseption86, mikeyww and 450 guests