question why command works everywhere (#IfWinActive)

Get help with using AutoHotkey and its commands and hotkeys
need4speed
Posts: 132
Joined: 22 Apr 2016, 06:50

question why command works everywhere (#IfWinActive)

30 May 2016, 11:19

I read the help file on KeyWait; I don't understand, why is the messagebox Pops up no matter which window is active?

Code: Select all

#IfWinActive ahk_class Notepad++
	KeyWait, d, D
		msgbox d is down
#IfWinActive

when using a hotkey the code works as expected (only if Notepad++ is active)

Code: Select all

#IfWinActive ahk_class Notepad++
~d::
	KeyWait, d, D
		msgbox d is down
return
#IfWinActive
anyone please enlighten me? :crazy:
User avatar
tidbit
Posts: 1196
Joined: 29 Sep 2013, 17:15
Location: USA

Re: question why command works everywhere (#IfWinActive)

30 May 2016, 11:32

https://autohotkey.com/docs/Tutorial.htm#s22
tutorial wrote:Sometime you might want a hotkey or hotstring to only work (or be disabled) in a certain window.
#if... things only work on hotkeys or hotstrings, not commands.
if you want it to work on commands you need to use IF (notice the lack of #)
G33kDude wrote:while 'If' handles what commands get run under what conditions, '#If' handles what hotkeys are enabled under what conditions
but if you use an if on your first code, chances are it'll close immediately since the IF fails and skips the keywait and it'll have nothing else to do, so it'll close.
rawr. fear me.
*poke*
Is it December 21, 2012 yet?
guest3456
Posts: 3153
Joined: 09 Oct 2013, 10:31

Re: question why command works everywhere (#IfWinActive)

31 May 2016, 21:57

https://autohotkey.com/docs/commands/_IfWinActive.htm

first line of that help page clearly says that that command is only for hotkeys

you probably want this:
https://autohotkey.com/docs/commands/WinActive.htm

need4speed
Posts: 132
Joined: 22 Apr 2016, 06:50

Re: question why command works everywhere (#IfWinActive)

01 Jun 2016, 01:47

thanks you are right. my bad, I looked only in the keywait help.

Return to “Ask For Help”

Who is online

Users browsing this forum: a1987zz, Bing [Bot], djuga, keylo, KilliK, mikeyww, Netocon, TXShooter and 48 guests