Jump to content

"Interrupt" Button


atzoref
 Share

Recommended Posts

  • Moderators

atzoref,

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

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

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

Link to comment
Share on other sites

Global $state = "pause"
HotKeySet( "A", "_pause")
HotKeySet( "S", "_play")
HotKeySet( "D", "_stop")

While 1 ;MainLoop
Switch $state
Case "pause"
;pause
Case "play"
;play
Case "stop"
;stop
EndSwitch

Func _play()
$state = "play"
EndFunc
Func _pause()
$state = "pause"
EndFunc
Func _stop()
$state = "stop"
EndFunc

Edited by jWalker
Link to comment
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 :)

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

  • 1 month later...

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

  • Moderators

nguyenkar,

What game are you using this play? :oops:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

  • Moderators

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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

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