Jump to content

Recommended Posts

Posted

Hi,

After my GUI is showing, I am trying to scripting so that it will auto click the $Button1 resides in the GUI which then will bring out an Inputbox, then it will auto fill up and click OK.

I have no problem just by clicking the $Button1, however, when I script to wait for the Inputbox the GUI will hang without further response.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 430, 218, 192, 124)
$Button1 = GUICtrlCreateButton("Button1", 120, 56, 209, 49)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
AdlibRegister("Myadlib", 250)

ControlClick($Form1, "", "[CLASS:Button; INSTANCE:1]")
WinWaitActive("halo", "enter you name")
ControlSetText("halo", "enter you name", "[CLASS:Edit; INSTANCE:1]", "David")
Sleep(100)
ControlClick("halo", "enter you name", "[CLASS:Button; INSTANCE:1]")
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $sName = InputBox("halo", "enter you name")
            If $sName <> "" Then MsgBox(0,"",$sName)
    EndSwitch
WEnd

 

Posted

Problem 1: Your WinWaitActive gets executed before reaching the GUI-Loop. So it waits for all eternity for the "case $Button1" to get executed.

Problem 2: InputBox means the script will pause until the user closes the Inputbox

So you'd need to run a second script which waits for the other script to make it's Inputbox or you could give the Inputbox the desired content:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 430, 218, 192, 124)
$Button1 = GUICtrlCreateButton("Button1", 120, 56, 209, 49)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

ControlClick($Form1, "", "[CLASS:Button; INSTANCE:1]")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $sName = InputBox("halo", "enter you name", "David")
            If $sName <> "" Then MsgBox(0,"",$sName)
    EndSwitch
WEnd

However, the user would have to click on ok by themselves.

Any of my own codes posted on the forum are free for use by others without any restriction of any kind. (WTFPL)

Posted (edited)

Hey guner7,

Edit: May not be relevant btw, sorry if so :)

I guess you are getting this behaviour due to InputBox blocking message loop.

https://www.autoitscript.com/autoit3/docs/functions/GUIRegisterMsg.htm

Warning: blocking of running user functions which executes window messages with commands such as "MsgBox()" can lead to unexpected behavior, the return to the system should be as fast as possible !!!

 

Edited by GokAy

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...