2016-03-15 159 views
1

我用tkinter編寫了一個簡約的python程序,當點擊一個按鈕時它會給出一個示例文本。我現在想的AutoIt執行該程序,然後單擊按鈕:鼠標點擊按鈕

#include <MsgBoxConstants.au3> 
#include <AutoItConstants.au3> 

CalcTime() 

Func CalcTime() 
    Run("dist/min_tk_app.exe") 
    Local $aPos = ControlGetPos("[CLASS:Button; INSTANCE:1]", "", "Edit1") 
    MsgBox($MB_SYSTEMMODAL, "", $aPos) 
    MouseClick($MOUSE_CLICK_LEFT, 324, 145, 1) 
EndFunc 

我收到這個信息:[CLASS:Button; INSTANCE:1],通過AutoIt的窗口信息應用。我總是隻收到0作爲$aPos的輸出。你知道這是爲什麼嗎?

回答

1

您正在使用錯誤的ControlGetPos

ControlGetPos ("title", "text", controlID) 

[CLASS:Button; INSTANCE:1]應儘可能controlID不要忘記窗口(重要的)的稱號!

不管怎麼說,而不是ControlGetPosMouseClick你應該使用ControlClick

$WinTitle = "" ; put your window title here MANDATORY or it will use active window 
$WinText = "" ;can be left empty 
ControlClick($WinTitle, $WinText, "[CLASS:Button; INSTANCE:1]") 
1

我假設您收到0作爲$aPos的輸出,因爲窗口還沒有。你可以嘗試該窗口上的工作之前,使用WinWait

Run("dist/min_tk_app.exe") 

; wait 10 seconds for the window to appear 
WinWait("[CLASS:YourApp]", "", 10) 

; maybe wait another second 
Sleep(1000) 

Local $aPos = ControlGetPos("[CLASS:Button; INSTANCE:1]", "", "Edit1") 
1

@如果地鐵的解決方案不工作,我會建議使用ControlFocus設置在控制焦點,然後ControlSend發送的控制ENTER鍵。通常OK按鈕被預先選擇。如果不是這種情況,那麼您可以發送TAB,直到按鈕獲得焦點並且發送進入。