Sign in to follow this  
Followers 0
atzoref

"Interrupt" Button

15 posts in this topic

Hi,

How can I make kind of interrupt button so when I will press on it,

it will run an interrupt function during the script process?

Share this post


Link to post
Share on other sites



atzoref,

The Interrupting a running function tutorial in the Wiki will explain all. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

For make sure, I cannot run OnEvent Interrupt Function of a button when other OnEvent Function of another button is already running?

Share this post


Link to post
Share on other sites

atzoref,

Correct. You can always use the trick shown in the third example in the Wiki page and start the function from within the main loop. If you do not want to do that then you have to use one of the 3 options (HotKey, Accelerator key, GUIRegisterMsg) described later in the Wiki page. ;)

Try and code something yourself - then post here if you get into difficulties. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

I read the examples but I don't know how to implement it.

I tell you my original idea: To implement PLAY, PAUSE, STOP buttons

so I need every button to change a state of the Script's Running status.

Every button has its "OnEvent" function.

During the main WHILE loop

PLAY is running the main Function, so I need an idea how make the PAUSE and STOP buttons to interrupt the "PLAY" function.

This is my problem.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

jWalker,

Can I do this example with GUI buttons or it is impossible?

Edited by atzoref

Share this post


Link to post
Share on other sites

Hmm good question...

you could implement the GUIGetMsg() into your play, pause and stop functions.

So it loops through this function and if another button is pressed then the Global value gets set and the other function gets called

If you don't understand what i mean, post your script and i will show you :)

Share this post


Link to post
Share on other sites

atzoref,

Here is a working example of how to do what you want: ;)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)

; Declare flags
Global $fPause = False, $fStop

; Create GUI
$hGUI = GUICreate("Test", 500, 500)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

$hPlay = GUICtrlCreateButton("Play", 10, 10, 80, 30)
GUICtrlSetOnEvent(-1, "_Play")
$hPause = GUICtrlCreateButton("Pause", 10, 50, 80, 30)
$hStop = GUICtrlCreateButton("Stop", 10, 90, 80, 30)

GUISetState()

; Intercept Windows command messages with our own handler
GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")

While 1
    Sleep(10)
WEnd

Func _Play()

    ; Clear flags
    $fStop = False
    $fPause = False

    ; Just for play simulation
    Static $iSec = 0

    While 1

        ; Simulate playing
        If @SEC <> $iSec Then
            $iSec = @Sec
            ConsoleWrite("Playing" & @CRLF)
        EndIf
        ; End of play simulation

        ; Look for PAUSE
        If $fPause Then
            ConsoleWrite("Paused" & @CRLF)
            ; Wait until flag is cleared
            Do
                ; Look for STOP while PAUSEed
                If $fStop Then
                    ConsoleWrite("Stop" & @CRLF)
                    Return
                EndIf
                Sleep(10)
            Until Not $fPause
        EndIf

        ; Look for Stop
        If $fStop Then
            ConsoleWrite("Stop" & @CRLF)
            Return
        EndIf

    WEnd

EndFunc

Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam)

    ; Get ControlID of pressed control
    Switch BitAND($wParam, 0x0000FFFF)
        ; If PAUSE pressed
        Case $hPause
            ; Toggle PAUSE flag
            $fPause = Not $fPause
        ; If Stop pressed
        Case $hStop
            ; Set STOP flag
            $fStop = True
    EndSwitch
    Return $GUI_RUNDEFMSG

EndFunc   ;==>_WM_COMMAND

Func _Exit()
    Exit
EndFunc

Now you should be able to adapt your code to fit in that framework. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Hi Melba23

How can I interrupt Start() func in side your func with many sleep() ? Help me please

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
; Declare flags
Global $fPause = False, $fStop
; Create GUI
$hGUI = GUICreate("Test", 500, 500)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
$hPlay = GUICtrlCreateButton("Play", 10, 10, 80, 30)
GUICtrlSetOnEvent(-1, "_Play")
$hPause = GUICtrlCreateButton("Pause", 10, 50, 80, 30)
$hStop = GUICtrlCreateButton("Stop", 10, 90, 80, 30)
GUISetState()
; Intercept Windows command messages with our own handler
GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")
While 1
    Sleep(10)
WEnd
Func _Play()
    ; Clear flags
    $fStop = False
    $fPause = False
    ; Just for play simulation
    Static $iSec = 0
    While 1
        ; Simulate playing
        If @SEC <> $iSec Then
            $iSec = @Sec
            ConsoleWrite("Playing" & @CRLF)
   Start() ; call sub function
        EndIf
        ; End of play simulation
        ; Look for PAUSE
        If $fPause Then
            ConsoleWrite("Paused" & @CRLF)
            ; Wait until flag is cleared
            Do
                ; Look for STOP while PAUSEed
                If $fStop Then
                    ConsoleWrite("Stop" & @CRLF)
                    Return
                EndIf
                Sleep(10)
            Until Not $fPause
        EndIf
        ; Look for Stop
        If $fStop Then
            ConsoleWrite("Stop" & @CRLF)
            Return
        EndIf
    WEnd
EndFunc
Func Start()
ControlSend('Untitled - Notepad','','[CLASSNN:Edit1]','Something...')
Sleep(2000)
ControlSend('Untitled - Notepad','','[CLASSNN:Edit1]','Something...')
Sleep(2000)
ControlSend('Untitled - Notepad','','[CLASSNN:Edit1]','Something...')
Sleep(2000)
ControlSend('Untitled - Notepad','','[CLASSNN:Edit1]','Something...')
Sleep(2000)
ControlSend('Untitled - Notepad','','[CLASSNN:Edit1]','Something...')
Sleep(2000)
ControlSend('Untitled - Notepad','','[CLASSNN:Edit1]','Something...')
Sleep(2000)
ControlSend('Untitled - Notepad','','[CLASSNN:Edit1]','Something...')
Sleep(2000)
ControlSend('Untitled - Notepad','','[CLASSNN:Edit1]','Something...')
Sleep(2000)
ControlSend('Untitled - Notepad','','[CLASSNN:Edit1]','Something...')
Sleep(2000)
ControlSend('Untitled - Notepad','','[CLASSNN:Edit1]','Something...')
Sleep(2000)
ControlSend('Untitled - Notepad','','[CLASSNN:Edit1]','Something...')
Sleep(2000)
ControlSend('Untitled - Notepad','','[CLASSNN:Edit1]','Something...')
Sleep(2000)
EndFunc
Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    ; Get ControlID of pressed control
    Switch BitAND($wParam, 0x0000FFFF)
        ; If PAUSE pressed
        Case $hPause
            ; Toggle PAUSE flag
            $fPause = Not $fPause
        ; If Stop pressed
        Case $hStop
            ; Set STOP flag
            $fStop = True
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_COMMAND
Func _Exit()
    Exit
EndFunc
Edited by nguyenkar

Share this post


Link to post
Share on other sites

nguyenkar,

What game are you using this play? :oops:

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

nguyenkar,

What game are you using this play? :oops:

M23

I make auto for the Flash Game, using control click and control send. It run smoothly but cannot stop, when I need to stop I must close it.

Please help me to fix this. Thanks

Share this post


Link to post
Share on other sites

nguyenkar, please see the forum rules here. We do not discuss game automation on this forum.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

nguyenkar,

What game are you using this play? :oops:

M23

Well that was fucking subtle.

Thread locked.

2 people like this

Share this post


Link to post
Share on other sites

Valik,

With a script that includes such things as

; Simulate playing

I did not feel that "subtlety" was a necessary characteristic of my response! :oops:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  
Followers 0