Run/Pause 脚本 当 "X" window 分别为 active/inactive

Run/Pause Script When an "X" window is active/inactive respectively

我编写的用于切换某些内容的简单代码。我目前正在尝试使此脚本仅在 Fallout4 之类的游戏存在时才起作用。当失去焦点时自动暂停 window.

*RButton::
*Control::
*Shift::

while (GetKeyState("Ctrl", "T") ^ GetKeyState("Shift", "T"))
{
    while (GetKeyState("RButton", "P"))
    {
        ;Some Action
    }
        ;Some Action
        return  
}
return

*F8::Suspend
*F9::Exitapp

SetTitleMatchMode, 2
#IfWinActive SomeApplication.exe
     ;Run This Script
#IfWinNotActive SomeApplication.exe
     ;Suspend+Pause This Script

return

Exit: 
    ExitApp 
Return

我无法让这部分与 Fallout4 一起工作,它根本检测不到它,但与记事本一起工作得很好,但我必须在#IfWinActive

之后手动执行该部分
 SetTitleMatchMode, 2
 #IfWinActive ahk_exe Fallout4.exe
         ;Run THIS Script
 #IfWinNotActive ahk_exe Fallout4.exe
         ;Suspend+Pause This Script

在这种情况下,您只需要使用#IfWinActive 指令使您的热键上下文相关,也就是说,使它们仅在定义的 window 处于活动状态时才有效:

#IfWinActive ahk_exe Fallout4.exe

    *RButton::
    *Control::
    *Shift::

    while (GetKeyState("Ctrl", "T") ^ GetKeyState("Shift", "T"))
    {
        while (GetKeyState("RButton", "P"))
        {
            ;Some Action
        }
            ;Some Action
            return  
    }
    return

    *F8::Suspend
    *F9::Exitapp

#IfWinActive ; turn off context sensitivity

https://www.autohotkey.com/docs/commands/_IfWinActive.htm