#IfWinActive v.s. if WinActive() Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
dsewq1LYJ
Posts: 116
Joined: 26 Aug 2014, 23:21

#IfWinActive v.s. if WinActive()

04 Oct 2016, 03:20

Hello everyone.

I got one really weird question...
My script is not "clear" and maybe not efficient, because I am using #IfWinActive foo and If WinActive() at one single script...
and now I want to improve my script better and more clearer, but which one is faster ?

Code: Select all

;~ 1
#IfWinActive foo
^c::return
#If
#IfWinActive bar
^c::return
#If

;~ 2
^c::
if WinActive("foo")
	return
else if WinActive("bar")
	return
return
User avatar
Nextron
Posts: 1391
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win10 AHK: Unicode x32

Re: #IfWinActive v.s. if WinActive()  Topic is solved

04 Oct 2016, 03:39

The second example is quicker, because it will not install a keyboard hook (negligibly) interrupting input and will not execute on the up event of the key. However it will not do what you want, so you have to use the first snippet of code, as only that will make the hotkey conditionally do nothing for two applications and not interfere otherwise.
The second example will always override the native function regardless of the application, check for two applications and do nothing in those cases and otherwise default to doing nothing also; breaking the copy functionality.
dsewq1LYJ
Posts: 116
Joined: 26 Aug 2014, 23:21

Re: #IfWinActive v.s. if WinActive()

04 Oct 2016, 05:42

Nextron wrote:The second example is quicker, because it will not install a keyboard hook (negligibly) interrupting input and will not execute on the up event of the key. However it will not do what you want, so you have to use the first snippet of code, as only that will make the hotkey conditionally do nothing for two applications and not interfere otherwise.
The second example will always override the native function regardless of the application, check for two applications and do nothing in those cases and otherwise default to doing nothing also; breaking the copy functionality.
Thank you so much ! OMG :shock:
I got it, and it's really important to me :dance:

Now I got a lot of stuff to do :headwall:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: peter_ahk, TAC109 and 351 guests