AutoHotKey IfWinActive无效

时间:2016-01-01 22:26:38

标签: autohotkey

我试图使用一个简单的脚本,该脚本仅在活动窗口打开时以及当您在该窗口中时(例如某些窗口模式游戏)才有效。因此脚本可以工作,但它也可以在活动窗口之外工作,例如在桌面或浏览器上也是如此。我不需要那个。我需要它才能在我设置的活动窗口中工作。

剧本:

RButton::rightMouseClick()
    rightMouseClick(){
        if WinActive("ahk_class Notepad") {
            WinMaximize
            Send, Some text.{Enter}
            return
        }
    }

因此,当您转到记事本并右键单击时,此示例有效。但是现在右键单击还没有在计算机上的任何其他地方工作?只有按住班次才能起作用吗?!

如果活动窗口是记事本,我该如何让这个脚本做出反应/工作/运行?而不是全球工作。

2 个答案:

答案 0 :(得分:2)

这是我的建议:

#If WinActive("ahk_class Notepad") ;if the window with the ahk_class "Notepad" is active
    RButton::                      ;this hotkey is only enabled while the above statement is true
        WinMaximize                ;maximize the active window
        Send, Some text.{Enter}    ;send some keyboard input
    Return                         ;end of the hotkey
#If                                ;end of the special "#If" statement

单独纠正缩进可以帮助理解代码。

答案 1 :(得分:1)

#IfWinActive ahk_class Notepad
RButton::
    WinMaximize
    Send, Some text.{Enter}
    Return
    #If