Page 1 of 1

Need help with WinGetTitle

Posted: 16 Jan 2023, 19:21
by alclarkey
[Mod edit: Topic moved to v2 help.]

I'm trying to get the window title of the active window, but my script returns nothing. What am I doing wrong?

Code: Select all

#UseHook 1
#MaxThreadsPerHotkey 4

global windowtitle := ""

f3::
{
global
windowtitle := WinGetTitle("A")
}

f4:: {
global
MsgBox windowtitle
}

Re: Need help with WinGetTitle

Posted: 16 Jan 2023, 20:35
by boiler
What you posted would not work in v1, which is the part of the forum where you posted and what your past posts look like you use. WinGetTitle is not a function in v1. It's a command. Look at the docs -- the proper version of the docs for the version you're using -- and follow the syntax shown.

Re: Need help with WinGetTitle

Posted: 16 Jan 2023, 21:17
by AHKStudent
some links, as boiler said, make sure you know what version you are using

https://www.autohotkey.com/docs/v1/lib/WinGetTitle.htm

https://www.autohotkey.com/docs/v2/lib/WinGetTitle.htm

Re: Need help with WinGetTitle

Posted: 16 Jan 2023, 21:19
by mikeyww
But OK in v2 if you're trying that.

Code: Select all

#Requires AutoHotkey v2.0
windowtitle := ""
F4::MsgBox windowtitle
F3:: {
 Global windowtitle := WinGetTitle("A")
 SoundBeep 1500
}
Some windows may not have a window title.

Re: Need help with WinGetTitle

Posted: 17 Jan 2023, 17:32
by alclarkey
I'm using V2 and I can't get a title from anything.

Re: Need help with WinGetTitle

Posted: 17 Jan 2023, 17:45
by alclarkey
Ok, solved it. Problem was the scope. Initialized the variable I was trying to use as a global inside my hotkey, and it worked.

Re: Need help with WinGetTitle

Posted: 18 Jan 2023, 06:40
by mikeyww