[Bug or lack of knowledge] can't execute code after context sensitive or hotstrings Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
viniam
Posts: 5
Joined: 18 Oct 2021, 20:20

[Bug or lack of knowledge] can't execute code after context sensitive or hotstrings

Post by viniam » 05 Oct 2022, 15:23

Hello there,
I found a problem where I can't get a MsgBox (or any code) working after a defined hotstring or after a #IfWinActive closing statement. Is this normal behavior?
I intended to run multiple macros from a single one, it works, but when I try the MsgBox after all the #Include, it doesn't run, because somewhere inside the #Include Hotstring.ahk or WinActive.ahk there are the hotstrings definition or the #ifWinActive, that blocks my code to execute said scripts.

Hotstring example:

Code: Select all

MsgBox, Test ; this does run

:*:...::
    LTrim(A_ThisHotkey,":oc?*")
    SendInput,{raw}…
Return

MsgBox, Test ; this does not run

:*:>email::
    LTrim(A_ThisHotkey,":oc?*")
    SendInput,{raw}%email%
Return

MsgBox, Test ; this also does not run
IfWinActive example:

Code: Select all

MsgBox, Test ; this does run

#IfWinActive ahk_exe Illustrator.exe
    $XButton1::
        Send, {F3}
    Return

#IfWinActive

MsgBox, Test ; this does not run

#IfWinActive ahk_exe inDesign.exe
    $WheelUp::
        BlockInput, On
        SendInput !{PGUP}
        BlockInput, Off
    Return
    
    MsgBox, Test ; this also does not run

    $!+WheelUp::AutoLeftClicks()
#IfWinActive

MsgBox, Test ; this also does not run
When I tried without context sensitive, it works, but makes so all the codes inside it run anywhere, which is not what I want.

Code: Select all

If WinActive("ahk.exe Illustrator.exe"){
    Code
}
MsgBox, Test ; this runs
IfGreater, A_TimeIdle, 6000, Send, {!F1} ; this too
Am I missing something?


viniam
Posts: 5
Joined: 18 Oct 2021, 20:20

Re: [Bug or lack of knowledge] can't execute code after context sensitive or hotstrings

Post by viniam » 05 Oct 2022, 22:49

Yeah, even though I read the Doc, I can't quite understand why it breaks my code sequence. I quit my idea for now, will run stuff before #Include/#IfWinActive/Hotkey/Hotstring assignment when necessary. (Maybe that's what's right?)

User avatar
boiler
Posts: 16900
Joined: 21 Dec 2014, 02:44

Re: [Bug or lack of knowledge] can't execute code after context sensitive or hotstrings

Post by boiler » 05 Oct 2022, 22:57

You only have to read and understand the first sentence at the link I posted. Can you read that and look back at your code and understand why the second MsgBox line never executes?

viniam
Posts: 5
Joined: 18 Oct 2021, 20:20

Re: [Bug or lack of knowledge] can't execute code after context sensitive or hotstrings

Post by viniam » 06 Oct 2022, 11:21

After the script has been loaded, it begins executing at the top line, continuing until a Return, Exit, the script's first hotkey/hotstring label, or the physical end of the script is encountered (whichever comes first)
Does that mean I won't be able to execute anything that appear after any of those?
If I make each include as a function and call then, would it work?

User avatar
boiler
Posts: 16900
Joined: 21 Dec 2014, 02:44

Re: [Bug or lack of knowledge] can't execute code after context sensitive or hotstrings

Post by boiler » 06 Oct 2022, 14:37

Why do you need to put them after those? Just put them all at the top. When are you wanting the MsgBox to execute? After the hotsring subroutine executes? Then you would put it inside that hotstring subroutine. You should explain when you expect various piece of code to execute. If you want it triggered by a hotstring, then put it inside the hotstring. The code flow of the script doesn't continue past the hotstring subroutine after it finishes.

What is in each #Include? When is it supposed to execute?

viniam
Posts: 5
Joined: 18 Oct 2021, 20:20

Re: [Bug or lack of knowledge] can't execute code after context sensitive or hotstrings

Post by viniam » 06 Oct 2022, 21:03

It's fine, the thing is that I though it ignored any returns inside the #include and wanted to run after all the includes, to run a special thing that is brought by a specific #include. Changing the order made it work as intended, thanks!

Post Reply

Return to “Ask for Help (v1)”