How do I return from inside an if/else block in Autohotkey?

若如初见. 提交于 2019-12-12 06:25:10

问题


Below is the code snippet I used. If you are doing something in a browser, it should detect that you are currently in a browser and copy the URL to the clipboard. If you are not in a browser, then since there is no URL there is no question of doing that.

Regardless what browser I am in, the first MessageBox is always outputting the value 0. However, the MessageBox inside the function never gets activated, that is "No browser detected" message is never displayed. The value therefore can't be zero, yet when I am in notepad the if function still gets processed.

if (Retrieve_Browser_Type <> 0) 
    {
        Send, {F6}
        Send, ^{ins}
        URL = %clipboard%
        MsgBox, % Retrieve_Browser_type
        MsgBox, URL copied: %URL%
    }

Retrieve_Browser_Type() {
    IfWinActive, ahk_class MozillaWindowClass return 1
    IfWinActive, ahk_class Maxthon3Cls_MainFrm return 2
    IfWinActive, ahk_class IEFrame return 3
    IfWinActive, ahk_class Chrome_WidgetWin_1 return 4
    MsgBox, No browser detected
    return 0
}

回答1:


It was a syntax mistake that thee compiler didn't detect. Instead of:

IfWinActive, ahk_class MozillaWindowClass return 1  

You ought to write:

IfWinActive, ahk_class MozillaWindowClass 
return 1


来源:https://stackoverflow.com/questions/18070686/how-do-i-return-from-inside-an-if-else-block-in-autohotkey

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!