Send action always runs, even when IF statement equates to false??

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
woodgrain
Posts: 8
Joined: 18 Apr 2016, 17:37

Send action always runs, even when IF statement equates to false??

18 Apr 2016, 17:59

Hi All,

Can someone please tell me what I'm doing wrong with this code?
No matter what I ask the if statement to match it always types E when I press `, even if it equates to false.

I need the send to only work on a specific domain. If my domain is XYZ then the below code will still send E when I type `. In fact, even if I pause the script it still replaces ` with E!!? The variable MyDomain returns the correct domain name in the msgbox.

Thanks!
_______________________________
EnvGet, MyDomain, USERDOMAIN
MsgBox, % MyDomain
if (MyDomain = "ABC")
{
#IfWinExists ahk_class Notepad
`::Send, E
}
______________________________
I've also tried
______________________________
EnvGet, MyDomain, USERDOMAIN
MsgBox, % MyDomain
if MyDomain = "ABC"
{
If WinExist("ahk_class Notepad")
{
`::Send, E
Return
}
Return
}
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Send action always runs, even when IF statement equates to false??

18 Apr 2016, 18:23

To define a context sensitive hotkey you can use #If outside the hotkey definition:

Code: Select all

EnvGet, MyDomain, USERDOMAIN
MsgBox, % MyDomain
#If (MyDomain = "ABC") ; context sensitive

`::
    If WinActive("ahk_class Notepad")
       Send, E
Return
OR:

Code: Select all

EnvGet, MyDomain, USERDOMAIN
MsgBox, % MyDomain
#If WinActive("ahk_class Notepad") ; context sensitive

`::
    If (MyDomain = "ABC")
        Send, E
Return
Guest

Re: Send action always runs, even when IF statement equates to false??

18 Apr 2016, 19:50

Thanks for clarifying the #if for me, I was trying to figure that out.
I'll give it a try again now.
Guest

Re: Send action always runs, even when IF statement equates to false??

18 Apr 2016, 20:06

Perfect, thank you! I also now see that I can use IF etc after ::, that's very useful!
Of note, when I pause the script the ` key is still sending E? I have to exit the script for it to stop applying, is that expected behavior?

Code: Select all

EnvGet, MyDomain, USERDOMAIN
#if MyDomain = "abc"
{
   `::
	  If WinExist("ahk_class Notepad")
		 Send, E
   Return
}
User avatar
Nextron
Posts: 1391
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win10 AHK: Unicode x32

Re: Send action always runs, even when IF statement equates to false??

19 Apr 2016, 01:03

Yes it is. You either have to suspend the script or make the following change. Note I moved the Notepad check to be conditional, this causes the ` key to retain its native function if notepad is closed opposed to blocking it.

Code: Select all

EnvGet, MyDomain, USERDOMAIN
#if MyDomain = "abc" && WinExist("ahk_class Notepad") && !A_IsPaused
`::Send, E

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Spawnova and 58 guests