首页 > 解决方案 > Autohotkey:当程序失去焦点时自动最小化程序

问题描述

我正在使用以下 Autohotkey 脚本 win 10 在程序失去焦点时自动最小化程序,但是即使我在同一个程序中打开子菜单或弹出选项,它仍然会最小化整个窗口。那么我怎样才能尊重该程序中的所有子窗口呢?或任何其他执行此操作的脚本。

#NoEnv
#Warn
var := true
SetTimer, subroutine, -1
return

subroutine:
WinWaitNotActive, ahk_exe word.exe
sleep, 2000     
if (var) {
    WinMinimize
    SetTimer, subroutine, -1
}
return

!t::SetTimer, subroutine, % (var:=not var) ? -1 : "Off" 
!x::ExitApp ; ALT+X terminates the script

标签: windows-10autohotkeyminimizelost-focus

解决方案


; autohotkey v1
#NoEnv
#Warn
#Persistent
SetTimer, subroutine, 5000

subroutine()
{
    If WinActive("ahk_class Notepad++")
    {
        ToolTip, "notepad++ active"
    }
    else
    {
        WinMinimize, ahk_class Notepad++
        ToolTip, "notepad++ not active auto minimize after 5 second"
    }
}

; autohotkey v2
SetTimer "subroutine", 5000

subroutine()
{
    If WinActive("ahk_class Notepad++")
    {
        ToolTip "notepad++ active"
    }
    else
    {
        WinMinimize "ahk_class Notepad++"
        ToolTip "notepad++ not active auto minimize after a while"
    }
}


推荐阅读