Kou
Kou

Reputation: 807

How to get the active window's title with AutoHotKey?

I wrote this short test code, but it didn't work. What am I doing wrong?

F12::
WinGetTitle, Title, A ;
MsgBox, "%Title%"

The displayed result was ""

Upvotes: 23

Views: 39015

Answers (6)

我零0七
我零0七

Reputation: 473

If anyone else want to find the active windows info by autohotkey

Just run WindowSpy.ahk

The location is in your folder of AutoHotkey.exe

Upvotes: 1

vitaliydev
vitaliydev

Reputation: 480

In AutoHotKey 2 you can use this:

title := WinGetTitle("A")  ; "A" matches "Active" window

In AutoHotKey 1 you can use:

WinGetActiveTitle, title

Upvotes: 3

Thierry Dalon
Thierry Dalon

Reputation: 916

Using WinGetActiveTitle or WinGetTitle will do. Note the output of WinGetTitle contains more than the window title. You might want to remove the ending part with the program name e.g." - Google Chrome".

WinGetActiveTitle, Title
StringGetPos,pos,Title,%A_space%-,R
if (pos != -1)
    Title := SubStr(Title,1,pos)

Upvotes: 0

Forivin
Forivin

Reputation: 15488

The best practice would probably be to use WinGetActiveTitle:

F12::
   WinGetActiveTitle, Title
   MsgBox, The active window is "%Title%".
return

Upvotes: 6

user3712978
user3712978

Reputation: 167

If you do not put in a return it will run down your whole file.

Probably something not running through later in it.

Don't think the ; will affect it.

Anything after a ; is omitted from code as a comment.

Upvotes: 3

Schwarzie2478
Schwarzie2478

Reputation: 2276

I removed a ; and added return and this worked...

F12::
WinGetTitle, title, A
MsgBox, "%title%"
return

Upvotes: 34

Related Questions