我想找个地方放
$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 StudiosStronghold KingdomsStrongholdKingdoms.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
我只需要声明他们输入的$Password供以后使用。
我试着把它放在Case $ButtonOk下面,但是它给出了一个关于变量没有被声明的错误。
放在$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 StudiosStronghold KingdomsStrongholdKingdoms.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