Why Hotkey command does not work inside #IfWinActive? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
rdllngr
Posts: 54
Joined: 22 Sep 2017, 09:39

Why Hotkey command does not work inside #IfWinActive?

14 Feb 2019, 16:28

By typing B, the hotkey works normally. After pressing A, B is deactivated. C reloads the script. This routine works perfectly.

Code: Select all

#SingleInstance Force

$a::
ToolTip, Tap B to disable B`, C to reload
Hotkey, $b, Disable_B, On
return

$b::
ToolTip, B enabled
Send, B
return

$c::
Reload
return

Esc::
ExitApp
return

Disable_B:
ToolTip, B disabled
return
However, when I try to restrict it to a program using #IfWinActive, the B hotkey is not disabled after pressing A.

Why does this happen with IfWinActive?

Code: Select all

#SingleInstance Force

DetectHiddenWindows, On
SetTitleMatchMode, 2
#IfWinActive, ahk_exe notepad.exe

$a::
ToolTip, Tap B to disable B`, C to reload
Hotkey, $b, Disable_B, On
return

$b::
ToolTip, B enabled
Send, B
return

$c::
Reload
return

Esc::
ExitApp
return

Disable_B: ; <--- B can not be disabled when there's IfWinActive
ToolTip, B disabled
return

#IfWinActive
Thank you.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Why Hotkey command does not work inside #IfWinActive?  Topic is solved

15 Feb 2019, 07:41

Because you have to use Hotkey, If, <the_condition>
rdllngr
Posts: 54
Joined: 22 Sep 2017, 09:39

Re: Why Hotkey command does not work inside #IfWinActive?

15 Feb 2019, 09:01

I think I got it. I was able to isolate Notepad. Thank you for the tip!

My code for test:

Code: Select all

#SingleInstance Force

$a::
Send, a
Hotkey, IfWinActive, ahk_exe notepad.exe
Hotkey, $a, Key_a, On
Hotkey, $b, Disable_B, On
return

$b::
Send, b
Hotkey, IfWinActive, ahk_exe notepad.exe
Hotkey, $b, Key_b, On
return

$c::
Send, c
Hotkey, IfWinActive, ahk_exe notepad.exe
Hotkey, $c, Key_c, On
return

Esc::
ExitApp
return

Key_a:
Send, a
ToolTip, Tap B to disable B`, C to reload
return

Key_B:
Send, b
ToolTip, B enabled
return

Key_C:
Send, c
ToolTip, Reloding...
Sleep, 50
Reload
return

Disable_B:
ToolTip, B disabled
return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], Panaku, Rohwedder, roysubs and 324 guests