朋友们,我希望当某个特定窗口空闲 10 分钟时,它应该首先激活该窗口,然后发送 f4 键。我使用一些在线软件,当该软件空闲或不活动 10 分钟时,它会注销,再次登录是非常繁琐和忙碌的工作,所以我希望当 10 分钟过去而没有任何活动(仅在该窗口上)时,该窗口应该被激活并且应该自动发送 f4 键。
窗口间谍中显示的窗口标题是这样的-
Finacle - 微软 Internet Explorer
ahk_class IEFrame
ahk_exe 浏览器
答案1
您可以尝试类似这样的方法...我无法测试。有很多因素可能会导致它无法正常工作,因此您可能需要进行一些实验。
首先启动脚本(它将保持运行),然后使用 F4 或 F10 激活 IE 窗口,之后您应该会看到工具提示弹出,并且它应该从上次手动激活后每 10 分钟重新激活一次。
#NoEnv
#Persistent
winFinacle := "Finacle - Microsoft Internet Explorer ahk_exe IEXPLORE.EXE"
return
#IfWinActive, %winFinacle%
~F4:: ; tilde allows pass-through of the keystroke to the program
~F10::
KeepFinacleActive:
ToolTip Activating Finacle...
sleep 1000
tooltip
; Enable timer to call itself after desired time once user kicks things off with initial key press
SetTimer, KeepFinacleActive, 600000 ; 10min * 60sec/min * 1000ms/sec = 600000
BlockInput, On ; block user input in case this happens in the middle of other user activity
WinActivate, %winFinacle%
WinWaitActive,,,2 ; wait a max of 2 seconds for it to be active
if not ErrorLevel ; if there was no error...
{
sleep 200 ; give IE some nominal time to load (adjust as needed)
SendInput {F10} ; send a keystroke (this will be a duplicate keystroke first time user executes manually)
}
else ; else if we couldn't find the window...
{
tooltip Couldn't find window during attempted activation...
sleep 2000
tooltip
}
BlockInput, Off
return
#IfWinActive ; disable for following commands (if any)