I have a situation where a hotkey command calls another hotkey command using the
Send command (in real life, this is used in Quick Access Popup "Snippets" that, in macro mode, can include hotkeys). Normally, a hotkey can call a second hotkey as shown in this piece of code. Pressing
Alt+F1 will show the message box for
Alt+F1 then show it a second time for
Alt+F2.
Code: Select all
#requires AutoHotkey v1.1
#SingleInstance,Force
Hotkey, !F1, DoIt
Hotkey, !F2, DoIt
return
DoIt:
MsgBox, %A_ThisLabel% with: %A_ThisHotkey%
if (A_ThisHotkey = "!F1")
Send, !{F2}
return
But when these hotkeys are monitored by a
Hotkey, If <condition>, the second hotkey is not executed, even if the condition is true. Would it be a bug?
Code: Select all
#requires AutoHotkey v1.1
#SingleInstance,Force
; Enable hotkeys only if CanDoIt() returns true
Hotkey, If, CanDoIt()
Hotkey, !F1, DoIt
Hotkey, !F2, DoIt
Hotkey, If
; Handle for the "Hotkey, If" condition
#If, CanDoIt()
#If
return
DoIt:
MsgBox, %A_ThisLabel% with: %A_ThisHotkey%
SendMode Event ; Input InputThenPlay Play
if (A_ThisHotkey = "!F1")
Send, !{F2}
return
CanDoIt() ; name of the function must match the #If handle above
{
return true
; return false
}
I tried with other Send modes (Input, InputThenPlay, Play) with the same result. I also tried with the
IfWinActive command (like
Hotkey, IfWinActive, ahk_group TestGroup) with the same result.