Jump to content

Basic Query: Controlling Script from GUI


baroim
 Share

Recommended Posts

Hi All,..i’ve been using Autoit to make a bot and I need to wrap it into a nice super simple GUI that consist of two buttons; start (to run the script) and stop (to stop the script). It also need to have a text box (integrated, below the buttons) that display every step of the workflow the script currently running on. In general the script looks like this:

; Capture the result area

$checksum = PixelChecksum(970,182,980,192)

$i = 0

While $i <= 10

; empty on 1-4

MouseClick ("left",369,858,1)

sleep(1)

; checking result

If $checksum = PixelChecksum(970,182,980,192) Then

$checksum = PixelChecksum(970,182,980,192)

Else

; first attempt recovery

MouseClick ("left",429,858,1)

sleep(1)

; second attempt recovery

MouseClick ("left",426,861,1)

sleep(1)

EndIf

; empty on 33-36

MouseClick ("left",372,858,1)

sleep(1)

; checking result

If $checksum = PixelChecksum(970,182,980,192) Then

$checksum = PixelChecksum(970,182,980,192)

Else

; first attempt recovery

MouseClick ("left",429,858,1)

sleep(1)

; second attempt recovery

MouseClick ("left",426,861,1)

sleep(1)

EndIf

Wend

I have searched the forum for similar script, but couldn’t find any, it was either too complicated, or irrelevant (im very new to programming). Any help would be much appreciated. Thanks

Link to comment
Share on other sites

you would have to use a hotkey setup to pause and start the script. Reason being, you cannot click on a gui button if your mouse is being forced to click in a different location

; Press Esc to terminate script, Pause/Break to "pause"

Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
#include <GUIConstantsEx.au3>
GUICreate("",150,100,-1,-1)
Global $update=GUICtrlCreateLabel("Waiting",10,45,150,20)
GUISetState(@SW_SHOW)

;;;; Body of program would go here ;;;;
GUICtrlSetData($update,"Capture the result area")
$checksum = PixelChecksum(970,182,980,192)

$i = 0
While $i <= 10

GUICtrlSetData($update,"empty on 1-4") 
MouseClick ("left",369,858,1)
sleep(1)

GUICtrlSetData($update,"checking result")
If $checksum = PixelChecksum(970,182,980,192) Then
$checksum = PixelChecksum(970,182,980,192)
Else
GUICtrlSetData($update,"first attempt recovery")
MouseClick ("left",429,858,1)
sleep(1)

GUICtrlSetData($update,"second attempt recovery")
MouseClick ("left",426,861,1)
sleep(1)

EndIf

GUICtrlSetData($update,"empty on 33-36")
MouseClick ("left",372,858,1)
sleep(1)

GUICtrlSetData($update,"checking result")
If $checksum = PixelChecksum(970,182,980,192) Then
$checksum = PixelChecksum(970,182,980,192)
Else
GUICtrlSetData($update,"first attempt recovery")
MouseClick ("left",429,858,1)
sleep(1)

GUICtrlSetData($update,"second attempt recovery")
MouseClick ("left",426,861,1)
sleep(1)

EndIf
Wend
;;;;;;;;

Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc

Func Terminate()
    Exit 0
EndFunc
Edited by kaotkbliss

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

you would have to use a hotkey setup to pause and start the script. Reason being, you cannot click on a gui button if your mouse is being forced to click in a different location

; Press Esc to terminate script, Pause/Break to "pause"

Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
#include <GUIConstantsEx.au3>
GUICreate("",150,100,-1,-1)
Global $update=GUICtrlCreateLabel("Waiting",10,45,150,20)
GUISetState(@SW_SHOW)

;;;; Body of program would go here ;;;;
GUICtrlSetData($update,"Capture the result area")
$checksum = PixelChecksum(970,182,980,192)

$i = 0
While $i <= 10

GUICtrlSetData($update,"empty on 1-4") 
MouseClick ("left",369,858,1)
sleep(1)

GUICtrlSetData($update,"checking result")
If $checksum = PixelChecksum(970,182,980,192) Then
$checksum = PixelChecksum(970,182,980,192)
Else
GUICtrlSetData($update,"first attempt recovery")
MouseClick ("left",429,858,1)
sleep(1)

GUICtrlSetData($update,"second attempt recovery")
MouseClick ("left",426,861,1)
sleep(1)

EndIf

GUICtrlSetData($update,"empty on 33-36")
MouseClick ("left",372,858,1)
sleep(1)

GUICtrlSetData($update,"checking result")
If $checksum = PixelChecksum(970,182,980,192) Then
$checksum = PixelChecksum(970,182,980,192)
Else
GUICtrlSetData($update,"first attempt recovery")
MouseClick ("left",429,858,1)
sleep(1)

GUICtrlSetData($update,"second attempt recovery")
MouseClick ("left",426,861,1)
sleep(1)

EndIf
Wend
;;;;;;;;

Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc

Func Terminate()
    Exit 0
EndFunc

kaotkbliss, thank you for your assistance, i will give this a try, thanks again.
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...