chx
chx

Reputation: 11790

How to detect whether an UWP app is really active?

I have this little Autohotkey script which toggles Bluetooth just fine:

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

but I am slightly bothered by the Sleep 300 in there. It seems despite the WinWaitActive the app is not really active and I need to wait for it and I couldn't find anything better than a specified set of time. What would be better to wait for?

Upvotes: 1

Views: 1278

Answers (1)

Relax
Relax

Reputation: 10636

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

Upvotes: 1

Related Questions