问题
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