#IfWinNotActive / WinActive with else

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
Manuhk
Posts: 3
Joined: 26 Mar 2023, 21:08

#IfWinNotActive / WinActive with else

Post by Manuhk » 26 Mar 2023, 21:17

Hello :D, which replaces #IfWinNotActive in version 2, or how to use an else in WinActive

in the following code if notepad is active
send ctrl+g
if not ctrl+s

Code: Select all

#HotIf WinActive("ahk_class Notepad")
^!+a::
{	
	Send "notepad"
	Send "^g"
}

User avatar
boiler
Posts: 16960
Joined: 21 Dec 2014, 02:44

Re: #IfWinNotActive / WinActive with else

Post by boiler » 26 Mar 2023, 21:31

Manuhk wrote: Hello :D, which replaces #IfWinNotActive in version 2, or how to use an else in WinActive

Code: Select all

#HotIf !WinActive("ahk_class Notepad")

Try working the solution to your other question knowing this.

User avatar
mikeyww
Posts: 26939
Joined: 09 Sep 2014, 18:38

Re: #IfWinNotActive / WinActive with else

Post by mikeyww » 26 Mar 2023, 21:33

Another option:

Code: Select all

^!+a:: {
 Send 'notepad'
 If WinActive('ahk_class Notepad')
      Send '^g'
 Else Send '^s'
}
These overall formats (syntax) are the same as for v1. Added are the quotation marks (expression format throughout) and the Hot in the directive.

Manuhk
Posts: 3
Joined: 26 Mar 2023, 21:08

Re: #IfWinNotActive / WinActive with else

Post by Manuhk » 28 Mar 2023, 08:38

Thank you very much, it works great

Post Reply

Return to “Ask for Help (v2)”