我想知道是否可以制作一个脚本,让其每 12 分钟聚焦一个特定的应用程序,然后立即将其最小化。
总结一下:
- 等待 12 分钟
- 让应用成为焦点
- 将其最小化(或者如果可能的话,使其重新聚焦上次使用的应用程序?)
到目前为止,我只发现最小化它将使之前的应用程序再次成为焦点。
最佳答案
是的,这绝对是您可以在 AutoHotkey 中执行的操作。下面的链接是您提到的特定项目的 AutoHotkey 帮助文档。
- 等待 12 分钟:
为此您至少有几个选择。您可以单独使用 Loop
和 Sleep
或 SetTimer
的组合。我推荐 SetTimer
,但熟悉其他两个也很有好处。
https://www.autohotkey.com/docs/commands/Loop.htm
https://www.autohotkey.com/docs/commands/Sleep.htm
https://www.autohotkey.com/docs/commands/SetTimer.htm
- 让应用成为焦点
- 将其最小化(或者如果可能的话,使其重新聚焦上次使用的应用程序?)
AutoHotkey中有很多窗口命令。这两个是针对您具体要求的:
https://www.autohotkey.com/docs/commands/WinActivate.htm
https://www.autohotkey.com/docs/commands/WinMinimize.htm
根据您需要聚焦窗口的原因,可能有不同的方法来完成您的需求。如果您需要每 12 分钟在某个窗口中输入一些内容,您也可以使用 ControlSend
而无需激活它。
这是一个帮助您入门的示例:
f1:: ; f1 will toggle your script to run
bT := !bT ; this is the toggle variable
If bT
{
GoSub , lTimer ; triggers the timer sub to run immediately since SetTimer has to wait for period to expire on first run
SetTimer , lTimer , 2500 ; this is in milliseconds, 12min = 720000ms
}
Else
SetTimer , lTimer , Off
Return
lTimer: ; timer sub
If WinExist( "EEHotkeys" ) ; change EEHotkeys to be the name of your window in all places shown
{
WinActivate , EEHotkeys
WinWaitActive , EEHotkeys
WinMinimize , EEHotkeys
}
Return
编辑:根据 samthecodingman 在评论中的建议,您也可以获取事件窗口的标题,激活您的窗口,然后重新激活原始窗口。
lTimer: ; timer sub
If WinExist( "EEHotkeys" ) ; change EEHotkeys to be the name of your window in all places shown
{
WinGetActiveTitle , sActiveWindow
WinActivate , EEHotkeys
WinWaitActive , EEHotkeys
WinActivate , %sActiveWindow%
}
Return
关于autohotkey - 如何在自动热键中使窗口处于焦点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54901859/