autohotkey - 如何在自动热键中使窗口成为焦点
问题描述
我想知道是否可以制作一个脚本,每 12 分钟将一个特定的应用程序聚焦,然后立即将其最小化。
所以总结一下:
- 等待 12 分钟
- 使应用程序成为焦点
- 最小化它(或者如果可能的话,让它重新关注上次使用的应用程序?)
到目前为止,我只发现最小化它会使以前的应用程序再次成为焦点。
解决方案
是的,这绝对是你可以在 AutoHotkey 中做的事情。下面的链接指向您提到的特定项目的 AutoHotkey 帮助文档。
- 等待 12 分钟:
为此,您至少有几个选择。您可以使用 and 的组合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
推荐阅读
- reactjs - ag-grid:如果接近到期日期,则为单元格着色
- shell - UNIX Shell 将 UNIX Shell 脚本中的变量设置为目录路径加文件名
- ios - 在按钮触摸上获取 CollectionViewCell 的 IndexPath
- spring-hateoas - 实体模型继承 Spring Hateoas 1.0
- quarkus - 程序化调度 - 最好的方法是什么?
- sql - 使用三个 case 表达式运行更新?
- javascript - 过滤标签以显示来自 Chart.js 的用户
- python - 获取功能创建的 enum.Enum 类的名称
- scala - 依赖注入模块初始化顺序中 Dev 和 Prod 模式的区别
- r - 如何在 tibble 列中找到最长的重复序列?