atzoref Posted January 29, 2012 Share Posted January 29, 2012 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? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 29, 2012 Moderators Share Posted January 29, 2012 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
atzoref Posted January 29, 2012 Author Share Posted January 29, 2012 For make sure, I cannot run OnEvent Interrupt Function of a button when other OnEvent Function of another button is already running? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 29, 2012 Moderators Share Posted January 29, 2012 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
atzoref Posted January 30, 2012 Author Share Posted January 30, 2012 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 More sharing options...
jWalker Posted January 30, 2012 Share Posted January 30, 2012 (edited) 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 January 30, 2012 by jWalker Link to comment Share on other sites More sharing options...
atzoref Posted January 30, 2012 Author Share Posted January 30, 2012 (edited) jWalker, Can I do this example with GUI buttons or it is impossible? Edited January 30, 2012 by atzoref Link to comment Share on other sites More sharing options...
jWalker Posted January 30, 2012 Share Posted January 30, 2012 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 More sharing options...
Moderators Melba23 Posted January 30, 2012 Moderators Share Posted January 30, 2012 atzoref, Here is a working example of how to do what you want: expandcollapse popup#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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
nguyenkar Posted March 22, 2012 Share Posted March 22, 2012 (edited) Hi Melba23 How can I interrupt Start() func in side your func with many sleep() ? Help me please expandcollapse popup#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 March 22, 2012 by nguyenkar Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 22, 2012 Moderators Share Posted March 22, 2012 nguyenkar, What game are you using this play? M23 Mat 1 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
nguyenkar Posted March 22, 2012 Share Posted March 22, 2012 nguyenkar,What game are you using this play? M23I 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 Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted March 22, 2012 Moderators Share Posted March 22, 2012 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 More sharing options...
Valik Posted March 22, 2012 Share Posted March 22, 2012 nguyenkar,What game are you using this play? M23Well that was fucking subtle.Thread locked. MariusN and Skitty 2 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 22, 2012 Moderators Share Posted March 22, 2012 Valik,With a script that includes such things as; Simulate playingI did not feel that "subtlety" was a necessary characteristic of my response! M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts