21

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 ""

Marc Stober
  • 10,237
  • 3
  • 26
  • 31
Kou
  • 777
  • 3
  • 8
  • 16
  • 1
    You simply need a space in front of the `;` for it to work, without the space the `;` is taken as part of the windows title – blackholyman Jan 22 '15 at 12:13

6 Answers6

34

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

F12::
WinGetTitle, title, A
MsgBox, "%title%"
return
Schwarzie2478
  • 2,186
  • 26
  • 30
5

The best practice would probably be to use WinGetActiveTitle:

F12::
   WinGetActiveTitle, Title
   MsgBox, The active window is "%Title%".
return
Stevoisiak
  • 23,794
  • 27
  • 122
  • 225
Forivin
  • 14,780
  • 27
  • 106
  • 199
3

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.

user3712978
  • 167
  • 2
  • 6
1

In AutoHotKey 2 you can use this:

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

In AutoHotKey 1 you can use:

WinGetActiveTitle, title
vitaliydev
  • 420
  • 4
  • 7
0

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)
Thierry Dalon
  • 779
  • 5
  • 21
0

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

我零0七
  • 315
  • 3
  • 6