2011-09-05 428 views
2

我有這樣AutoHotkey的腳本:AutoHotkey的:如何避免「失去焦點」問題

#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 

我使用這個腳本在啓動時爲自動登錄一個工具。

問題是 - 如果這個腳本正在工作(約2秒鐘+應用程序啓動時間(大約30秒),總共32秒),某些其他程序會彈出一個關於某事的窗口(如可用的新更新或防病毒索賠或任何其他)腳本不起作用,因爲窗口「用戶識別」的焦點丟失。

如何解決此問題?我應該使用其他工具(哪一個),或者有可能使用autohotkey解決這個問題?

感謝

回答

1

我用這對我完全生成代碼AutoScriptWriter程序:

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

然而ControlSend可能更好的選擇

+1

高興你得到它的工作。就像提示一樣 - 查看ControlSend和ControlClick命令。如果在當前腳本輸入數據的同時竊取焦點,則會導致問題。將擊鍵/點擊直接發送到控件更加可靠,並且不需要窗口具有焦點。 –