如何在自动热键中使窗口成为焦点

时间:2019-02-27 09:18:11

标签: autohotkey

我想知道是否可以制作一个脚本,使它每12分钟将一个特定的应用程序放在焦点上,然后立即将其最小化。

所以总结一下:

  • 等待12分钟
  • 使应用程序成为重点
  • 将其最小化(或在可能的情况下使其重新聚焦上次使用的应用?)

到目前为止,我只发现将其最小化会使上一个应用再次成为焦点。

1 个答案:

答案 0 :(得分:0)

是的,这绝对是您可以在AutoHotkey中执行的操作。下面的链接指向您提到的特定项目的AutoHotkey帮助文档。

  • 等待12分钟:

为此您至少有两个选择。您可以单独使用LoopSleepSetTimer的组合。我建议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