Nested #IfWinActive Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
MauroG
Posts: 60
Joined: 11 Jul 2017, 05:52

Nested #IfWinActive

14 Feb 2019, 13:33

Is it possible to use nested #IfWinActive? I'm trying this code:

Code: Select all

#IfWinActive Calibre
ENTER::
{
	Send {ENTER}
	Sleep 250
	#IfWinActive ahk_exe explorer.exe
	{
		Gosub, CheckErrorLevel
		Return
	}
	Return
}
where the idea is, if Calibre is active and I press Enter, the script send Enter; then, if after 250 ms an Windows Explorer windows has become active the script runs a subroutine, otherwise does nothing. If I run this script, it runs only if Calibre is active, but runs the subroutine despite an explorer.exe window being active.
DRocks
Posts: 565
Joined: 08 May 2018, 10:20

Re: Nested #IfWinActive  Topic is solved

14 Feb 2019, 13:49

Code: Select all

#IfWinActive Calibre
ENTER::
{
	Send {ENTER}
	
	;Sleep 250
	;#IfWinActive ahk_exe explorer.exe
	
	WinWaitActive, ahk_exe explorer.exe,,0.3 ; wait for 0.3sec until this win is active. It fails if not active after 0.3 sec
	if (! ErrorLevel)
	{
		Gosub, CheckErrorLevel
		Return
	}
	Return
}
MauroG
Posts: 60
Joined: 11 Jul 2017, 05:52

Re: Nested #IfWinActive

14 Feb 2019, 13:55

Thanks, it works; why it doesn't works with #IfWinActive?
User avatar
Scr1pter
Posts: 1272
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: Nested #IfWinActive

14 Feb 2019, 14:00

I think because you cannot have 2 active windows at once.

Cheers!
Please use [code][/code] when posting code!
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], RandomBoy, scriptor2016 and 354 guests