Oleg Vazhnev
Oleg Vazhnev

Reputation: 24067

autohotkey: how to avoid "focus lost" problem

I have such autohotkey script:

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
Run file.exe              # takes ~30 seconds to start
WinWait User identification
Sleep 1000
Send administrator{tab}
Sleep 1000
Send password
Click 38, 196

I'm using this script at start-up to auto-logon one utility.

The problem is - if when this script is working (for about 2 seconds + application start-up time (about 30 seconds) 32 seconds in total) some other program pop-up a window about something (like new update available or antivirus claim or anything) the script doesn't work because the focus of the window "User identification" is lost.

How to workaround this problem? Should I use another tool (which one) or it's possible to solve this problem using autohotkey?

Thanks

Upvotes: 2

Views: 3588

Answers (1)

Oleg Vazhnev
Oleg Vazhnev

Reputation: 24067

I've used AutoScriptWriter program that generates code for me perfectly:

Run file.exe
WinWait, User identification,
IfWinNotActive, User identification, , WinActivate, User identification, 
WinWaitActive, User identification, 
Send, administrator{TAB}password{ENTER}

However ControlSend likely better choice

Upvotes: 1

Related Questions