Jump to content


IfWinActive/If WinActive()/#IfWinActive


  • Please log in to reply
7 replies to this topic

#1 Drugoy

Drugoy
  • Guests

Posted 17 July 2012 - 06:33 PM

Hi, I got a problem binding the script to work out only if some specific window is active.
I ran WinSpy on that window and here is the screenshot:
Posted Image
Please, ignore "Vortex Studio" - I need the script to work in some sub-windows of it, and they have different title, so binding to "Vortex Studio" is incorrect.
The script should be somehow bound to the ahk_class, but the problem is that only first part of it is static (WindowsForms), the rest is dynamic.

Please, someone tell me how to write the "if win active" condition for my case correctly.

#2 Ohnitiel

Ohnitiel
  • Members
  • 664 posts

Posted 17 July 2012 - 06:38 PM

Maybe checking the text in them, if there is something that appears in all of them.

#3 Drugoy

Drugoy
  • Guests

Posted 17 July 2012 - 06:46 PM

no, I need to bind the script to the ahk_class, who's first part is common for all of them.

#4 Guests

  • Guests

Posted 17 July 2012 - 06:56 PM

Look at the RegEx option of

Sets the matching behavior of the WinTitle parameter in commands such as WinWait.
Source: http://www.autohotke...leMatchMode.htm



#5 dylan904

dylan904
  • Members
  • 706 posts

Posted 17 July 2012 - 07:03 PM

http://www.autohotke...ds/GroupAdd.htm
As I said before, use GroupAdd, they all contain "WindowsForms" in their ahk_class.
You say you think this would Loop forever, if somebody else would run and tell how many times it looped for them, it looped 12 times, and took less < .2 seconds for for me...
WinGet, List, List
Loop, %List%
{
	WinGetClass, Class, % "ahk_id " List%A_Index%
	If (InStr(Class, "WindowsForms"))
		GroupAdd, WindowsForms, % "ahk_class " . Class
}

#If WinActive("ahk_group WindowsForms")

F1:: 
MsgBox Active!
Return

#If


#6 HotKeyIt

HotKeyIt
  • Fellows
  • 6119 posts

Posted 17 July 2012 - 07:29 PM

Instead:
#If WinActive("ahk_group WindowsForms")
I would prefer using #IfWinActive :!:
It might need less resources/cpu.
#IfWinActive ahk_group WindowsForms


#7 dylan904

dylan904
  • Members
  • 706 posts

Posted 17 July 2012 - 07:36 PM

I believe they both use the GetActiveWindow function within User32.dll, just in a different manner. Neither should be processed faster than the other AFAIK.

#8 Drugoy

Drugoy
  • Guests

Posted 19 July 2012 - 03:21 PM

Look at the RegEx option of

Sets the matching behavior of the WinTitle parameter in commands such as WinWait.
Source: http://www.autohotke...leMatchMode.htm

Thanks!

dylan904,
my code is better:
SetTitleMatchMode RegEx
#IfWinActive ahk_class WindowsForms