如何检测UWP应用程序是否真的有效?

时间:2018-02-09 06:54:36

标签: autohotkey

我有这个小小的Autohotkey脚本可以很好地切换蓝牙:

SendMode Input
Run, ms-settings:bluetooth
WinWaitActive, Settings
Sleep 300
Send,{Tab}{Space}
WinClose, A

但我对那里的Sleep 300感到有些困扰。似乎尽管WinWaitActive应用程序并不是真正活跃的,但我需要等待它,我找不到比指定时间更好的东西。等待什么会更好?

1 个答案:

答案 0 :(得分:0)

SendMode Input
Run, ms-settings:bluetooth
WinWait, Settings  ; or:
/* 
WinWait, Settings,, 2 ; wait 2 seconds maximally until the specified window exists
if ErrorLevel ; if the command timed out
{
    MsgBox, WinWait timed out.
    return
}
*/
IfWinNotActive,  Settings, ,WinActivate, Settings
WinWaitActive, Settings  ; or:
/* 
WinWaitActive, Settings,, 2 ; wait 2 seconds maximally  until the specified window is active
if ErrorLevel
{
    MsgBox, WinWaitActive timed out.
    return
}
*/
; Sleep 300 ; needed in some programs that may not react immediately after activated
Send,{Tab}{Space}
WinClose, A

https://autohotkey.com/docs/commands/WinWaitActive.htm