2013-05-25 22 views
0

我試圖找到一個地方,AutoIt的GUICtrlRead

$Password = GUICtrlRead($PasswordInput) 

內的

Func BeginningGUI() 
    #Region ### START Koda GUI section ### Form= 
    $Form1 = GUICreate("Stronghold Kingdoms", 248, 95, -1, -1) 
    $PasswordInput = GUICtrlCreateInput("Password", 8, 32, 233, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_PASSWORD)) 
    $ButtonOk = GUICtrlCreateButton("OK", 86, 64, 75, 25, $BS_NOTIFY) 
    $ButtonCancel = GUICtrlCreateButton("Cancel", 167, 64, 75, 25, $BS_NOTIFY) 
    $EnterPassLabel = GUICtrlCreateLabel("Please Enter Your Stronghold Kingdoms Password", 0, 12, 241, 17, 0) 
    GUISetState(@SW_SHOW) 
    #EndRegion ### END Koda GUI section ### 

    While 1 
    $nMsg = GUIGetMsg() 
    Switch $nMsg 
    Case $GUI_EVENT_CLOSE 
     Exit 
    Case $ButtonCancel 
     Exit 
    Case $ButtonOk 
     OpenSHK() 
     Exit 
    EndSwitch 
    WEnd 
EndFunc 

Func OpenSHK() 
    Run("C:\Program Files (x86)\Firefly Studios\Stronghold Kingdoms\StrongholdKingdoms.exe") 
    WinWaitActive("Stronghold Kingdoms") 
    Sleep(5000) 
    Send($Password) 
    MouseClick("left",927,163) 
    Sleep(5000) 
    MouseClick("left",1112,371) 
    WinWaitActive("Stronghold Kingdoms - World 8") 
    sleep(10000) 
EndFunc 

我只需要聲明一下他們的供以後使用$密碼進入。

我試着把它放在Case $ ButtonOk下面,但是它給出了一個關於變量未被聲明的錯誤。

+0

你嘗試了什麼,爲什麼它不起作用? –

+0

後來在程序中我試着發送($ Password),但是它說變量沒有被定義。我在OpenSHK()的正上方嘗試過,但沒有成功。 – NathanG

回答

0

把它放在$ ButtonOK之後被點擊時,調用OpenSHK()前:

Func BeginningGUI() 
    GLOBAL $Password 
    ... 
    $nMsg = GUIGetMsg() 
    Switch $nMsg 
    Case $GUI_EVENT_CLOSE 
     Exit 
    Case $ButtonCancel 
     Exit 
    Case $ButtonOk 
     $Password = GUICtrlRead($PasswordInput)    
     OpenSHK() 
     Exit 
    EndSwitch 
    WEnd 
EndFunc 

您需要已宣佈$Password變量第一個(像我一樣用GLOBAL在功能代碼的開始),或修改您的OpenSHK()函數以接受它作爲參數,如OpenSHK($Password)。在第二種情況下,您可以簡單地在BeginningGUI函數的開頭添加LOCAL $Passenger而不是GLOBAL

Func BeginningGUI() 
    LOCAL $Password 
    ... 
    $nMsg = GUIGetMsg() 
    Switch $nMsg 
    Case $GUI_EVENT_CLOSE 
     Exit 
    Case $ButtonCancel 
     Exit 
    Case $ButtonOk 
     $Password = GUICtrlRead($PasswordInput)    
     OpenSHK($Password) 
     Exit 
    EndSwitch 
    WEnd 
EndFunc 

Func OpenSHK($Password) 
    Run("C:\Program Files (x86)\Firefly Studios\Stronghold Kingdoms\StrongholdKingdoms.exe") 
    WinWaitActive("Stronghold Kingdoms") 
    Sleep(5000) 
    Send($Password) 
    MouseClick("left",927,163) 
    Sleep(5000) 
    MouseClick("left",1112,371) 
    WinWaitActive("Stronghold Kingdoms - World 8") 
    sleep(10000) 
EndFunc 
+0

給予此錯誤: 線51(文件「(路徑腳本): 發送($密碼) 發送(^ ERROR 錯誤:沒有被宣佈使用可變 – NathanG

+0

閱讀我的最後一段,我必須有當您發佈您的評論時,我一直在寫:-) –

+0

我剛剛編輯了主要帖子以包含整個腳本 當我把OpenSHK($密碼)給了我「錯誤:函數調用中的參數數量不正確。」 – NathanG