【问题标题】:Run/Pause Script When an "X" window is active/inactive respectively当“X”窗口分别处于活动/非活动状态时运行/暂停脚本
【发布时间】:2019-12-20 06:18:09
【问题描述】:

我编写了一个简单的代码来切换某些东西。我目前正试图让这个脚本只在它存在时才能在像 Fallout4 这样的游戏上运行。当它失去对该窗口的焦点时自动暂停。

*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

【问题讨论】:

    标签: autohotkey


    【解决方案1】:

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

    #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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-10
      • 1970-01-01
      • 2014-12-07
      • 1970-01-01
      • 2017-07-14
      相关资源
      最近更新 更多