如何从Autohotkey的if/else块内部返回? [英] How do I return from inside an if/else block in Autohotkey?

查看:323
本文介绍了如何从Autohotkey的if/else块内部返回?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我使用的代码段.如果您正在浏览器中执行某项操作,它将检测到您当前正在浏览器中,并将URL复制到剪贴板.如果您不在浏览器中,那么由于没有URL,因此毫无疑问.

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.

无论我使用的是哪种浏览器,第一个MessageBox始终输出值0.但是,该函数内部的MessageBox永远不会被激活,即永远不会显示未检测到浏览器"消息.因此该值不能为零,但是当我在记事本中时,if函数仍然会被处理.

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
}

推荐答案

这是编译器未检测到的语法错误. 代替:

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

IfWinActive, ahk_class MozillaWindowClass return 1  

您应该写:

IfWinActive, ahk_class MozillaWindowClass 
return 1

这篇关于如何从Autohotkey的if/else块内部返回?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆