Jump to content

Cancel button


Recommended Posts

Hi,

show your script, please.

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Hi,

show your script, please.

So long,

Mega

I want to put it in here somewhere......

For $I = 0 To $NumTimeFields - 1
        $cf = GUICtrlRead($CoordsField[$I])
        $hrs = GUICtrlRead($HourFields[$I])
        $mins = GUICtrlRead($MinuteFields[$I])
        $secs = GUICtrlRead($SecondFields[$I])
        $pausetime= ($hrs*3600)+($mins*60)+$secs
        If $cf = "" Then ContinueLoop
        Sleep(6000)
        MouseClick("right", StringLeft($cf, StringInStr($cf, ",") - 1), StringTrimLeft($cf, StringInStr($cf, ",")))
        Sleep(3000)
        MouseClick("left", (StringLeft($cf, StringInStr($cf, ",") - 1) + $XSpot) , (StringTrimLeft($cf, StringInStr($cf, ",")) + $YSpot))
        
    While $pausetime > 0 
            $totalsecpause = INT($pausetime)
            $hrspause= Int($totalsecpause/3600)
            $minpause = Int(($totalsecpause/60) - $hrspause*60)     
            $secpause = int($totalsecpause - ($minpause*60) - $hrspause*3600) ;working
            
            ToolTip("Now running number " & ($I + 1) & "....Waiting " & $hrspause & " hours, " & $minpause & " minutes, " & $secpause & " seconds.", 210, 3)
        
        Sleep(1000)
        $pausetime = $pausetime - 1
    WEnd
$pausetime = 0  
       tooltip("")

   Next
Link to comment
Share on other sites

  • Moderators

I see lots of examples of exit buttons etc but nothing I want. What should I look for in the helpfile?

You've succeeded in posting code, but nothing relevant to your request. Do we write the GUI ourselves, and guess how you are using it, or would you like to actually post a working example of what you are trying to do. A word of advice, don't make us work to help you, the easier you make it, the faster and more accurate the responses are.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

Well this is what I've got but no luck.......

I have no clue of how to go about this cancel button so thats why I asked for some help. Maybe I just want a push in the right direction.

CODE
Func Start()
    ToolTip("")
    
    Local $AllFieldEmpty = True
    For $I = 0 To UBound($CoordsField) - 1
        If GUICtrlRead($CoordsField[$I]) <> "" Then $AllFieldEmpty = False
    Next
    If $AllFieldEmpty Then
        MsgBox(16, "Error", "Please enter Coordinates")
        Return
    EndIf

    For $I = 0 To $NumTimeFields - 1
        $cf = GUICtrlRead($CoordsField[$I])
        $hrs = GUICtrlRead($HourFields[$I])
        $mins = GUICtrlRead($MinuteFields[$I])
        $secs = GUICtrlRead($SecondFields[$I])
        $pausetime= ($hrs*3600)+($mins*60)+$secs
        If $cf = "" Then ContinueLoop
        Sleep(6000)
        MouseClick("right", StringLeft($cf, StringInStr($cf, ",") - 1), StringTrimLeft($cf, StringInStr($cf, ",")))
        Sleep(3000)
        MouseClick("left", (StringLeft($cf, StringInStr($cf, ",") - 1) + $XSpot) , (StringTrimLeft($cf, StringInStr($cf, ",")) + $YSpot))
        
    While $pausetime > 0 
            $totalsecpause = INT($pausetime)
            $hrspause= Int($totalsecpause/3600)
            $minpause = Int(($totalsecpause/60) - $hrspause*60)     
            $secpause = int($totalsecpause - ($minpause*60) - $hrspause*3600) ;working
            $cancel = GUICtrlCreateButton("CANCEL", 128, $Y + 100, 45, 30)
    GUICtrlSetOnEvent($cancel, "")
    GUISetState()
    Select
        case $cancel = 1
            exitloop
    EndSelect
            ToolTip("Now running number " & ($I + 1) & "....Waiting " & $hrspause & " hours, " & $minpause & " minutes & " & $secpause & " seconds.", 210, 3)
        
        Sleep(1000)
        $pausetime = $pausetime - 1
    WEnd
$pausetime = 0  
       tooltip("")

   Next
        
      MsgBox(48 + 0, "", "Skill training completed.")
    
EndFunc
:) Might start with actually making a GUI... :whistle:

And if there is one, you're still not practicing the "here's some code that works but doesn't work rule". A working example of your issue in a small scale ... rather than your entire code is what I was referring to.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

HI,

does this example help?

HotKeySet("3", "_exit")
HotKeySet("1", "_start")
HotKeySet("2", "_cancel")
_start()
Func _start()
    While 1
        Sleep(100)
        ToolTip("Here I am", 0, 0, "TOOLTIP", 1)
    WEnd
EndFunc   ;==>_start
Func _exit()
    Exit (0)
EndFunc   ;==>_exit
Func _cancel()
    While 1
        ToolTip("Doing nothing", 0, 0, "CANCEL", 1)
        Sleep(100)
    WEnd
EndFunc   ;==>_cancel

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

  • Moderators

1. What are you doing here? It's one big mess.

2. You can't use GUIOnEventMode with GUIGetMsg()

3. You keep recreating the button over and over.

4. I still don't even see a GUI.

Are you just taking bits and pieces from other scripts and hoping it works?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

1. This mess will get cleaned up once I get it working. I did ask ages ago for help on that but it doesnt matter atm.

2. Ok

3. Ok, will mess around with it some more

4. I posted the whole code above with the gui!!!

Please, I dont want to post the code again as the topic is just full of code and nothing else. I just need to know what I'm doing wrong and how to fix it.

Thanx

Link to comment
Share on other sites

  • Moderators

4. I posted the whole code above with the gui!!!

I might be blind... but do you care to point out where the hell you see GUICreate() at (Can't really have a GUI without creating it first can you?)?
CODE
While $pausetime > 0 
            $totalsecpause = INT($pausetime)
            $hrspause= Int($totalsecpause/3600)
            $minpause = Int(($totalsecpause/60) - $hrspause*60)     
            $secpause = int($totalsecpause - ($minpause*60) - $hrspause*3600) ;working
            $cancel = GUICtrlCreateButton("CANCEL", 128, $Y + 100, 45, 30)
    GUICtrlSetOnEvent($cancel, "cancel")
    GUISetState()
    
            ToolTip("Now running number " & ($I + 1) & "....Waiting " & $hrspause & " hours, " & $minpause & " minutes & " & $secpause & " seconds.", 210, 3)
        $msg = GUIGetMsg()
    Select
        
        Case $msg = $exit
            terminate()
        Case $msg = $cancel
            cancel()
    EndSelect       
        Sleep(1000)
        $pausetime = $pausetime - 1
    WEnd
$pausetime = 0  
       tooltip("")

   Next
        
      MsgBox(48 + 0, "", "completed.")
    
EndFunc  

    
;Paste coords
Func Paste()
    Send(ClipGet())
EndFunc   ;==>Paste

Func cancel()
    While 1
        Sleep(1000)
        ToolTip("")
    WEnd
EndFunc   ;==>_cancel

Func Terminate()
    Exit
EndFunc   ;==>Terminate
Just in case I really am missing it...

Please, I dont want to post the code again as the topic is just full of code and nothing else. I just need to know what I'm doing wrong and how to fix it.

Thanx

I'm not asking you to do something repetitive, I simply asked to post something that is specific to the question you have... something that would actually work if we fixed it, rather than us having to add to it (Such as actually create a GUI).

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Just in case I really am missing it...

I'm not asking you to do something repetitive, I simply asked to post something that is specific to the question you have... something that would actually work if we fixed it, rather than us having to add to it (Such as actually create a GUI).

The GuiCreate() is there now

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
Link to comment
Share on other sites

  • Moderators

The GuiCreate() is there now

You still had me questioning myself... so I was "made" to go out of my way and look at everything posted, and in post #6 the code was there... pfft : :whistle:

Edit:

Just too much wrong in this for me to go through line by line, I cleaned it up a tad, and could only guess what you were trying to do... follow this code, compare it to yours, since you know what you really want to do, and what is supposed to happen (I don't), you may get something out of it and understand how to fix it:

CODE
#include <GUIConstants.au3>
#Include <Misc.au3>
#include <Date.au3>
AutoItSetOption("MouseCoordMode", 1)
;Use Mouse Coordinates relative to:
;1-rel to screen
HotKeySet("{ENTER}", "Paste")
;master gui vars
$master_gui_width = 235
$master_gui_hight = 270
; variables group
$default_group_width = 140
$x_var_group = 5
$y_var_group = 10
$var_group_width = $default_group_width
$var_group_hight = $master_gui_hight - 100
;positions vars group
$pdefault_group_width = ($master_gui_width - $default_group_width)
$px_var_group = 146
$py_var_group = 10
$pvar_group_width = $pdefault_group_width - 10
$pvar_group_hight = $master_gui_hight - 100
; = END DEFINE VARIABLES
; ===== START MASTER GUI
GUICreate("=- Test -=", $master_gui_width, $master_gui_hight, 1100, 230)
WinSetOnTop("=- Test -=", "", 1)
; MENU
GUICtrlCreateMenu("Menu &One")
GUICtrlCreateMenu("Menu &Two")
GUICtrlCreateGroup("Times", $x_var_group, $y_var_group, $var_group_width, $var_group_hight)
GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group
GUICtrlCreateGroup("Positions", $px_var_group, $py_var_group, $pvar_group_width, $pvar_group_hight)
GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group
;Hrs, secs title
$widthCell = 100
GUICtrlCreateLabel("Hrs.  Mins.  Secs.", 50, 30)
Local Const $NumTimeFields = 3 ; can be up to 10
Local $HourFields[$NumTimeFields]
Local $MinuteFields[$NumTimeFields]
Local $SecondFields[$NumTimeFields]
Local $ProgressBar[$NumTimeFields]
Local $CoordsField[$NumTimeFields]
Local $XSpot, $YSpot, $cancel
$widthCellb = 40
$diff = 22
For $I = 0 To $NumTimeFields - 1
    Local $Y = $y_var_group + $diff * ($I + 2) - 3
    Local $Label = ' Skill ' & $I + 1 & '.'
    GUICtrlCreateLabel($Label, $x_var_group + 2, $Y + 3, $widthCellb)
    $HourFields[$I] = GUICtrlCreateInput('', 50, $Y, 18, 17, $ES_NUMBER)
    $MinuteFields[$I] = GUICtrlCreateInput('', 79, $Y, 18, 17, $ES_NUMBER)
    $SecondFields[$I] = GUICtrlCreateInput('', 108, $Y, 18, 17, $ES_NUMBER)
    $CoordsField[$I] = GUICtrlCreateInput("", 158, $Y, 60, 17)
Next
$exit = GUICtrlCreateButton("EXIT", 188, $Y + 100, 45, 30)
$start = GUICtrlCreateButton("START", 78, $Y + 100, 45, 30)
GUISetState()
$XSpot = Random(25, 140)
$YSpot = Random(6, 12)
GUISetState()
;Mouse movements/coords
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE Or $msg = $exit
            Exit
        Case $msg = $start
            Start()
    EndSelect
    $pos = MouseGetPos()
    ToolTip("" & $pos[0] & ", " & "" & $pos[1])
    Sleep(10)
    If _IsPressed(10) Then ; if SHIFT is pressed
        $pos = MouseGetPos()
        ClipPut($pos[0] & "," & $pos[1])
    EndIf
WEnd
;When Start button pressed....
Func Start()
    ToolTip("")
    Local $AllFieldEmpty = True
    For $I = 0 To UBound($CoordsField) - 1
        If GUICtrlRead($CoordsField[$I]) <> "" Then $AllFieldEmpty = False
    Next
    If $AllFieldEmpty Then
        MsgBox(16, "Error", "Please enter Coordinates")
        Return
    EndIf
    Local $cancel = GUICtrlCreateButton("CANCEL", 128, $Y + 100, 45, 30)
    For $I = 0 To $NumTimeFields - 1
        $cf = GUICtrlRead($CoordsField[$I])
        $hrs = GUICtrlRead($HourFields[$I])
        $mins = GUICtrlRead($MinuteFields[$I])
        $secs = GUICtrlRead($SecondFields[$I])
        $pausetime= ($hrs * 3600) + ($mins * 60) + $secs
        If $cf = "" Then ContinueLoop
        Sleep(6000)
        MouseClick("right", StringLeft($cf, StringInStr($cf, ",") - 1), StringTrimLeft($cf, StringInStr($cf, ",")))
        Sleep(3000)
        MouseClick("left", (StringLeft($cf, StringInStr($cf, ",") - 1) + $XSpot) , (StringTrimLeft($cf, StringInStr($cf, ",")) + $YSpot))
        While $pausetime > 0
            $totalsecpause = Int($pausetime)
            $hrspause = Int($totalsecpause / 3600)
            $minpause = Int(($totalsecpause / 60) - $hrspause * 60)
            $secpause = Int($totalsecpause - ($minpause * 60) - $hrspause * 3600)
            If GUIGetMsg() = $cancel Then
                GUICtrlDelete($cancel)
                Return ''
            EndIf
            ToolTip("Now running number " & ($I + 1) & "....Waiting " & $hrspause & " hours, " & $minpause & " minutes & " & $secpause & " seconds.", 210, 3)
            Sleep(1000)
            $pausetime = $pausetime - 1
        WEnd
        $pausetime = 0
        ToolTip("")
    Next
    GUICtrlDelete($cancel)
    MsgBox(48 + 0, "", "completed.")
EndFunc   ;==>Start
;Paste coords
Func Paste()
    Send(ClipGet())
EndFunc   ;==>Paste
Func Terminate()
    Exit
EndFunc   ;==>Terminate
Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Thanx for your reply. I posted what I wanted to do, posted the whole script (yes, #post6). Sorry thought everyone reads every topic from the first post to get all the info.

Anyways, how can I stop (cancel) the countdown loop when the cancel button is clicked, thats all I ask :whistle:

Link to comment
Share on other sites

  • 2 weeks later...

So how does one cancel an operation (such as this) so that more details can be inputted and then restarted from the beginning???? I got no idea how to make the damn thing cancel an operation....

Obviously every1 has NFI. Edited by NutherNoob
Link to comment
Share on other sites

I have been trying to figure it out, but the code is a jumble. As soon as a do one thing, i realize that in order for my technique to work, i have to edit 3 other parts of your code. The key is, don't use sleeps. I am working on it now, i will see what i can do.

EDIT

I edited your script to instantly respond to the cancel button and i still have no idea what it is supposed to do other than click awkwardly in places with random variations.

CODE
#include <GUIConstants.au3>
#Include <Misc.au3>
#include <Date.au3>

Global $b_Cancelled =  False

AutoItSetOption("MouseCoordMode", 1)
;Use Mouse Coordinates relative to:
;1-rel to screen
HotKeySet("{ENTER}", "Paste")
;master gui vars
$master_gui_width = 235
$master_gui_hight = 270
; variables group
$default_group_width = 140
$x_var_group = 5
$y_var_group = 10
$var_group_width = $default_group_width
$var_group_hight = $master_gui_hight - 100
;positions vars group
$pdefault_group_width = ($master_gui_width - $default_group_width)
$px_var_group = 146
$py_var_group = 10
$pvar_group_width = $pdefault_group_width - 10
$pvar_group_hight = $master_gui_hight - 100
; = END DEFINE VARIABLES
; ===== START MASTER GUI
GUICreate("=- Test -=", $master_gui_width, $master_gui_hight, 1100, 230)
WinSetOnTop("=- Test -=", "", 1)
; MENU
GUICtrlCreateMenu("Menu &One")
GUICtrlCreateMenu("Menu &Two")
GUICtrlCreateGroup("Times", $x_var_group, $y_var_group, $var_group_width, $var_group_hight)
GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group
GUICtrlCreateGroup("Positions", $px_var_group, $py_var_group, $pvar_group_width, $pvar_group_hight)
GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group
;Hrs, secs title
$widthCell = 100
GUICtrlCreateLabel("Hrs.  Mins.  Secs.", 50, 30)
Local Const $NumTimeFields = 3 ; can be up to 10
Local $HourFields[$NumTimeFields]
Local $MinuteFields[$NumTimeFields]
Local $SecondFields[$NumTimeFields]
Local $ProgressBar[$NumTimeFields]
Local $CoordsField[$NumTimeFields]
Local $XSpot, $YSpot, $cancel
$widthCellb = 40
$diff = 22
For $I = 0 To $NumTimeFields - 1
    Local $Y = $y_var_group + $diff * ($I + 2) - 3
    Local $Label = &apos; Eg &apos; & $I + 1 & &apos;.&apos;
    GUICtrlCreateLabel($Label, $x_var_group + 2, $Y + 3, $widthCellb)
    $HourFields[$I] = GUICtrlCreateInput(&apos;&apos;, 50, $Y, 18, 17, $ES_NUMBER)
    $MinuteFields[$I] = GUICtrlCreateInput(&apos;&apos;, 79, $Y, 18, 17, $ES_NUMBER)
    $SecondFields[$I] = GUICtrlCreateInput(&apos;&apos;, 108, $Y, 18, 17, $ES_NUMBER)
    $CoordsField[$I] = GUICtrlCreateInput("", 158, $Y, 60, 17)
Next
$exit = GUICtrlCreateButton("EXIT", 188, $Y + 100, 45, 30)
$start = GUICtrlCreateButton("START", 78, $Y + 100, 45, 30)
GUISetState()
$XSpot = Random(25, 140)
$YSpot = Random(6, 12)
GUISetOnEvent($GUI_EVENT_CLOSE, "Terminate")

GUISetState()
;Mouse movements/coords
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE Or $msg = $exit
            Exit
        Case $msg = $start
            Start()
    EndSelect
    $pos = MouseGetPos()
    ToolTip("" & $pos[0] & ", " & "" & $pos[1])
    Sleep(10)
    If _IsPressed(10) Then ; if SHIFT is pressed
        $pos = MouseGetPos()
        ClipPut($pos[0] & "," & $pos[1])
    EndIf
WEnd
;When Start button pressed....
Func Start()
    Startup()
    Local $i_Timestamp
    Local $AllFieldEmpty = True
    For $I = 0 To UBound($CoordsField) - 1
        If GUICtrlRead($CoordsField[$I]) <> "" Then $AllFieldEmpty = False
    Next
    If $AllFieldEmpty Then
        MsgBox(16, "Error", "Please enter Coordinates")
        Return 0
    EndIf
    Local $cancel = GUICtrlCreateButton("CANCEL", 128, $Y + 100, 45, 30)
    GUICtrlSetOnEvent($cancel,"STOP")
    For $I = 0 To $NumTimeFields - 1
        If $b_Cancelled = True Then Return 0
        $cf = GUICtrlRead($CoordsField[$I])
        $hrs = GUICtrlRead($HourFields[$I])
        $mins = GUICtrlRead($MinuteFields[$I])
        $secs = GUICtrlRead($SecondFields[$I])
        $pausetime= ($hrs * 3600) + ($mins * 60) + $secs
        If $cf = "" Then ContinueLoop
        $i_Timestamp = TimerInit()
        While TimerDiff($i_Timestamp) <= 6000
            If $b_Cancelled = True Then
                Cleanup($cancel)
                Return 0
            EndIf
            sleep(10)
        WEnd
        MouseClick("right", StringLeft($cf, StringInStr($cf, ",") - 1), StringTrimLeft($cf, StringInStr($cf, ",")))
        $i_Timestamp = TimerInit()
        While TimerDiff($i_Timestamp) <= 3000
            If $b_Cancelled = True Then
                Cleanup($cancel)
                Return 0
            EndIf
            sleep(10)
        WEnd
        MouseClick("left", (StringLeft($cf, StringInStr($cf, ",") - 1) + $XSpot) , (StringTrimLeft($cf, StringInStr($cf, ",")) + $YSpot))
        $i_Timestamp = TimerInit()
        While $pausetime > 0
            If $b_Cancelled = True Then
                Cleanup($cancel)
                Return 0
            EndIf
                If TimerDiff($i_Timestamp) >= 1000 Then;this means that at least one second has passed
                    $totalsecpause = Int($pausetime)
                    $hrspause = Int($totalsecpause / 3600)
                    $minpause = Int(($totalsecpause / 60) - $hrspause * 60)
                    $secpause = Int($totalsecpause - ($minpause * 60) - $hrspause * 3600)
       
                    ToolTip("Now running number " & ($I + 1) & "....Waiting " & $hrspause & " hours, " & $minpause & " minutes & " & $secpause & " seconds.", 210, 200)
                    $pausetime = $pausetime - 1
                Endif
            Sleep(10)
        WEnd
        $pausetime = 0
        ToolTip("")       
    Next
    Cleanup($cancel)
    MsgBox(48 + 0, "", "completed.")
    Return 1
EndFunc   ;==>Start

Func Paste()
    Send(ClipGet())
EndFunc   ;==>Paste

Func STOP()
    $b_Cancelled =  True
EndFunc

Func Startup()
    ;place all the stuff that you want done when it first starts in here
    $b_Cancelled =  False
    Opt("GUIOnEventMode",1)
    ToolTip("")
EndFunc
Func Cleanup($cancel)
    ;place everything in here you want the script to do to get it out of the processing mode
    ;since $cancel was a local variable, i passed the local variable to this function as a parameter
    GUICtrlDelete($cancel)
    Opt("GUIOnEventMode",0)
EndFunc

Func Terminate()
    Exit
EndFunc   ;==>Terminate

I hope that gives you some idea of how to get things to stop instantly.

Edited by The Kandie Man

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

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...