2015-10-08 16 views
3

當我點擊一個新窗口按鈕時,它總是在Windows 7 64位操作系統的後臺打開。如何在pyautoit中顯示總是出現在背景中而不是前景的窗口?

對於我的自動化任務,我需要將該窗口置於前臺。

以下是我pyautoit代碼:

autoit.send("{TAB 2}") 
sleep(3) 
autoit.send("{ENTER}") # After this step new window appears in background 
Wnd = autoit.win_wait("[CLASS:#32770]", 15) 
autoit.win_activate(Wnd)   
sleep(5) 
autoit.send("{ENTER}") 

我試圖win_wait和win_activate,如下圖所示:

Wnd = autoit.win_wait("[CLASS:#32770]", 15) 
autoit.win_activate(Wnd) 

但我得到以下錯誤:

WindowsError: exception: access violation reading 0x00000001 

然後我嘗試瞭如下URL所示的「regedit」選項:

http://ask.brothersoft.com/when-i-open-a-program-window-sometimes-it-opens-in-the-background-instead-of-the-foreground-253939.html 

但沒有用。我仍然看到同樣的問題。

任何人都可以幫我解決這個問題嗎?

+0

嘗試不同直接從Autoit運行。 isHandle Winactivate等。如果可行,那麼在你的py腳本中使用那個。 – Xenobiologist

回答

1

我會做這樣的:

AutoIt.Send("{TAB 2}") 
Sleep(3) 
AutoIt.Send("{ENTER}") 
AutoIt.WinWaitActive("[CLASS:#32770]", 15) 
AutoIt.WinActivate("[CLASS:#32770]") 
Sleep(5) 
AutoIt.Send("{ENTER}") 

Or use Alt-Tabs

AutoIt.Send("{TAB 2}") 
Sleep(3) 
AutoIt.Send("{ENTER}") 
Sleep(1) 
AutoIt.Send("{ALT DOWN}") 
AutoIt.Send("{TAB}") 
AutoIt.Send("{ALT UP}") 
Sleep(5) 
AutoIt.Send("{ENTER}") 

也不要使用類,只需要使用像窗口的名稱:

AutoIt.WinWaitActive("Setup", 15) 
+0

感謝您的回答。我也嘗試過。但窗口出現在後臺。無法帶來這一方面。錯誤:AutoItError:等待激活窗口超時。有任何想法來解決這個問題嗎? – rcubefather

+0

您是否嘗試使用windowname而不是CLASS?你能手動激活窗口嗎? – IkeRoyle

+0

是的。我可以手動激活窗口。我也嘗試過使用Window名稱。我無法把它帶到前面。 – rcubefather

相關問題