AutoHotKey:如何确定某个窗口是否已经与之交互过

时间:2016-02-09 15:08:26

标签: autohotkey

我正在制作一个AutoHotKey脚本,如果满足某些条件,它会关闭一个窗口。

首先,我的任务是将其设置为关闭窗口,如果计算机没有与之交互,比如5分钟。 AutoHotKey提供一个变量,用于检查用户是否与计算机进行过任何交互,该变量为A_TimeIdle。每次用户与计算机交互时,它都会更新为0,然后在用户不与计算机交互时显着增加。

我现在需要的是A_TimeIdle,但用户与特定窗口而不是整个计算机进行交互。 autohotkey提供这样的东西吗?有没有办法检查窗口有多长时间处于非活动状态呢?

2 个答案:

答案 0 :(得分:0)

这样的事情:

#Persistent
SetTimer, check_for_window
return

    check_for_window:
IfWinNotExist, ahk_class Notepad
{
    Tooltip
    return
}
IfWinActive, ahk_class Notepad
{
    SetTimer, check_for_window, off
    Tooltip
    WinWaitNotActive, ahk_class Notepad
    SetTimer, time_window_has_been_inactive
}
return

    time_window_has_been_inactive:
Loop 60
{
    Sleep 100
    IfWinActive, ahk_class Notepad
        return
}
SetTimer, time_window_has_been_inactive, off
IfWinExist, ahk_class Notepad
{
    Tooltip, Notepad has been inactive for 6 seconds
    ; do sth
}
SetTimer, check_for_window, on
return

另见: Minimize Inactive Windows

答案 1 :(得分:-1)

使用IfWinExist命令。

也许您不知道窗口是否正在启动,所以我建议您插入循环以尝试不同的时间。

i:=0
while(i < 5){
   IfWinExist, "Title"
   i := i + 1
   Sleep, 200 ;Wait a bit for the next comparison
}

另一个有用的命令是WinWait。您可以在此处查看定义:https://autohotkey.com/docs/commands/WinWait.htm

IfWinExist:https://autohotkey.com/docs/commands/WinExist.htm

相关问题