Sign in to follow this  
Followers 0
epicfail

adding GUI to my bot?

16 posts in this topic

hello im trying to add a GUI to my bot. My bot has sleep in it when it waits 4 the next click and then a sleep 4 6 hours. I tryed to make a gui that has start and stop on it but once the bot starts the stop button dosnt work how would i make it so i can get it to work?

Share this post


Link to post
Share on other sites



When using sleep that pauses the whole script to pause, including the GUI. What I think your looking for is:

GuiSetOnEvent.

Look at it in the help file.

Share this post


Link to post
Share on other sites

welli need it to sleep cos i have mouse clicks and need it to wait/sleep before the next click

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

You can split up a sleep command to ensure that gui events keep coming through.

_Sleep(8000) ; sleep for 8 seconds but GUI messages can still come through : ) : )  : )

Func _Sleep($wait, $delay = 10)
   $init = TimerInit()
   While TimerDiff($init) < $wait
      Sleep($delay)
   Wend
EndFunc

I'm not 100% sure on this but I think GUIOnEventMode breaks through the sleep anyway, making this useless.

Edit: Yep, this works:

Opt("GUIOnEventMode", 1)

$hWnd = GUICreate("Win", 200, 200)
$hButton = GUICtrlCreateButton("WinButton", 10, 10, 180, 180)
GUICtrlSetOnEvent($hButton, "Buttonclick")

GUISetState(@SW_SHOW, $hWnd)

Sleep(10000)

Func Buttonclick()
    GUICtrlSetData($hButton, "You clicked me.")
EndFunc

Here's how to solve it without concurrency (is a little less accurate probably, but who cares lol :D )

$hWnd = GUICreate("Win", 200, 200)
$hButton = GUICtrlCreateButton("WinButton", 10, 10, 180, 180)

GUISetState(@SW_SHOW, $hWnd)

_Sleep(10000) ; sleep for 10 seconds but GUI messages can still come through : ) : )  : )

Func _Sleep($wait, $delay = 10)
   $init = TimerInit()
   While TimerDiff($init) < $wait
      Sleep($delay)
      ApplicationDoEvents()
   Wend
EndFunc

Func ApplicationDoEvents()
    $hMsg = GUIGetMsg()
    Switch $hMsg
        Case -3 ; $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            Buttonclick()
    EndSwitch
EndFunc

Func Buttonclick()
    GUICtrlSetData($hButton, "You clicked me.")
EndFunc
Edited by Manadar

Share this post


Link to post
Share on other sites

thankyou :D but the problem is that i i have the button exit when im using sleep it dont exit.

Share this post


Link to post
Share on other sites

cant get it to work if im still using _sleep to wait 4 my next mouse click the my exit button dont work

Share this post


Link to post
Share on other sites

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Run_Obfuscator=y
#Obfuscator_Parameters=/cs
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
Local $loop = 0

Opt("WinWaitDelay",100)
Opt("WinTitleMatchMode",4)
Opt("WinDetectHiddenText",1)
Opt("MouseCoordMode",0)
#include <IsChecked.au3>
#include <Timers.au3>
#include <IE.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 329, 123, 192, 124)
$Input1 = GUICtrlCreateInput("Email", 72, 16, 185, 21)
$Input2 = GUICtrlCreateInput("Password", 72, 40, 185, 21, BitOR($ES_PASSWORD,$ES_AUTOHSCROLL))
$Button1 = GUICtrlCreateButton("Start Bot", 56, 88, 105, 25, $WS_GROUP)
$Button2 = GUICtrlCreateButton("Exit", 168, 88, 105, 25, $WS_GROUP)
GUICtrlSetOnEvent($Button2, "_EXIT")
$Checkbox1 = GUICtrlCreateCheckbox("Save Email & Password", 72, 64, 129, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


_Sleep(10000) ; sleep for 10 seconds but GUI messages can still come through : ) : )  : )

Func _Sleep($wait, $delay = 10)
   $init = TimerInit()
   While TimerDiff($init) < $wait
      Sleep($delay)
      ApplicationDoEvents()
   Wend
EndFunc

Func ApplicationDoEvents()
    $hMsg = GUIGetMsg()
    Switch $hMsg
        Case -3 ; $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            start()
    EndSwitch
EndFunc

Func start()
    $oIE = _IECreate ("www.Mysite.com")
$HWND = _IEPropertyGet($oIE, "hwnd")
WinSetState($HWND, "", @SW_MAXIMIZE)

_IELoadWait ($oIE)
$oform = _IEFormGetObjByName($oIE, "menubar_login")
$oQuery = _IEFormElementGetObjByName($oform, "email")
$o_Query = _IEFormElementGetObjByName($oform, "pass")

$username = GUICtrlRead($Input1)
$password = GUICtrlRead($Input2)

_IEFormElementSetValue($oQuery, $username)
_IEFormElementSetValue($o_Query, $password)

Send("{TAB}{ENTER}")

_IELoadWait ($oIE)
MouseMove(765,391)
MouseDown("left")
MouseUp("left")
_Sleep(8000)
MouseMove(775,367)
MouseDown("left")
MouseUp("left")
_Sleep(8000)
MouseMove(774,380)
MouseDown("left")
MouseUp("left")
_Sleep(8000)
MouseMove(344,256)
MouseDown("left")
MouseUp("left")
_Sleep(8000)
MouseMove(394,363)
MouseDown("left")
MouseUp("left")
_IEQuit ($oIE)

EndFunc


Func _EXIT()
    Exit
EndFunc

Share this post


Link to post
Share on other sites

so there nothing u can do? cos i was planing to do a 7 hour sleep at the end of it and loop it

Share this post


Link to post
Share on other sites

It could still get stuck in _IELoadWait for about 2 seconds.

The rest all works. The GUI stays for 10 seconds and then it closes, unless you press the button.

Share this post


Link to post
Share on other sites

no i want it to be able to stop the running scrit ad exit the gui when its sleeping waiting 4 the next click

Share this post


Link to post
Share on other sites

well i tested it itdont exit if the sleep is running

Share this post


Link to post
Share on other sites

You have to use either GUIOnEventMode or you use GUIGetMsg. I have shown examples of both, but I think you interpreted it as being the same thing.

If you use GUIGetMsg (you do in the code you posted above) you can't use functions like GUICtrlSetOnEvent or GUISetOnEvent.

Local $loop = 0

Opt("WinWaitDelay",100)
Opt("WinTitleMatchMode",4)
Opt("WinDetectHiddenText",1)
Opt("MouseCoordMode",0)
#include <Timers.au3>
#include <IE.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 329, 123, 192, 124)
$Input1 = GUICtrlCreateInput("Email", 72, 16, 185, 21)
$Input2 = GUICtrlCreateInput("Password", 72, 40, 185, 21, BitOR($ES_PASSWORD,$ES_AUTOHSCROLL))
$Button1 = GUICtrlCreateButton("Start Bot", 56, 88, 105, 25, $WS_GROUP)
$Button2 = GUICtrlCreateButton("Exit", 168, 88, 105, 25, $WS_GROUP)
$Checkbox1 = GUICtrlCreateCheckbox("Save Email & Password", 72, 64, 129, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


_Sleep(10000) ; sleep for 10 seconds but GUI messages can still come through : ) : )  : )

Func _Sleep($wait, $delay = 10)
   $init = TimerInit()
   While TimerDiff($init) < $wait
      Sleep($delay)
      ApplicationDoEvents()
   Wend
EndFunc

Func ApplicationDoEvents()
    $hMsg = GUIGetMsg()
    Switch $hMsg
        Case -3 ; $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            start()
        Case $Button2
            _Exit()
    EndSwitch
EndFunc

Func start()
    $oIE = _IECreate ("www.Mysite.com")
    $HWND = _IEPropertyGet($oIE, "hwnd")
    WinSetState($HWND, "", @SW_MAXIMIZE)

    _IELoadWait ($oIE)
    $oform = _IEFormGetObjByName($oIE, "menubar_login")
    $oQuery = _IEFormElementGetObjByName($oform, "email")
    $o_Query = _IEFormElementGetObjByName($oform, "pass")

    $username = GUICtrlRead($Input1)
    $password = GUICtrlRead($Input2)

    _IEFormElementSetValue($oQuery, $username)
    _IEFormElementSetValue($o_Query, $password)

    Send("{TAB}{ENTER}")

    _IELoadWait ($oIE)
    MouseMove(765,391)
    MouseDown("left")
    MouseUp("left")
    _Sleep(8000)
    MouseMove(775,367)
    MouseDown("left")
    MouseUp("left")
    _Sleep(8000)
    MouseMove(774,380)
    MouseDown("left")
    MouseUp("left")
    _Sleep(8000)
    MouseMove(344,256)
    MouseDown("left")
    MouseUp("left")
    _Sleep(8000)
    MouseMove(394,363)
    MouseDown("left")
    MouseUp("left")
    _IEQuit ($oIE)

EndFunc


Func _EXIT()
    Exit
EndFunc

And don't say "it doesn't work" when it clearly does work in both of the examples I posted. You just copy pasted it wrong.

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0