Jump to content

adding GUI to my bot?


epicfail
 Share

Recommended Posts

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?

Link to comment
Share on other sites

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
Link to comment
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

Link to comment
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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...