使用autoIt讓window focus在特定程式(視窗)

這邊有兩個眉角:

1. 最好先使用$aaa = WinWait("程式(視窗)名")確定目標視窗已執行,再使用WinActivate($aaa)讓window focus在此視窗上。

2. 最好先用BlockInput(True) 和 BlockInput(False)包起來,避免script執行中因為user控制或其他程式開啟,導致focus跑掉的情況。

範例:

 

Example()

Func Example()
; Do blockInput
BlockInput(True)      ; Run Notepad     Run("notepad.exe")     ; Wait 10 seconds for the Notepad window to appear.     Local $hWnd = WinWait("[CLASS:Notepad]", "", 10)     ; Activate the Notepad window using the handle returned by WinWait.     WinActivate($hWnd)     ; Close the Notepad window using the handle returned by WinWait.     WinClose($hWnd)

; Release BlockInput BlockInput(False) 
EndFunc   ;==>Example

 

 

--

參考自 https://www.autoitscript.com/autoit3/docs/functions/WinActivate.htm

http://stackoverflow.com/questions/22436919/autoit-and-winwaitactive

--

arrow
arrow
    全站熱搜

    dizzy03 發表在 痞客邦 留言(0) 人氣()