hoangakavn Posted April 20, 2018 Share Posted April 20, 2018 (edited) I have a question, when i click button pause not work but when i press hotkey f3 then pause script, this is my code, i want when i click button pause then script pause . Tks All expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 336, 72, 192, 124) $btn_begin = GUICtrlCreateButton("Start Click", 16, 16, 137, 33) $btn_pause = GUICtrlCreateButton("Pause / Resume", 184, 16, 137, 33) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 HotKeySet("{f1}","begin") Sleep(50) HotKeySet("{f3}","pause") Sleep(50) $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $btn_begin batdau() Case $btn_pause pause() EndSwitch WEnd Func begin() Global $g_bPaused = False For $i=1 to 10 while 1 MsgBox($MB_SYSTEMMODAL, "Title", "This message box will timeout after 10 seconds or select the OK button.", 10) Sleep(500) ExitLoop WEnd Next Sleep(50) EndFunc Func pause() $g_bPaused = Not $g_bPaused While $g_bPaused Sleep(100) ToolTip('Script is Pause"', 500, 500) WEnd EndFunc Edited April 20, 2018 by hoangakavn Link to comment Share on other sites More sharing options...
BrewManNH Posted April 20, 2018 Share Posted April 20, 2018 Try this, it's much better than what you have. expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> Global $g_bPaused = False ; <<<<<<<<<< Global variables should be declared outside of functions. HotKeySet("{f1}", "begin") HotKeySet("{f3}", "pause") #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 336, 72, 192, 124) $btn_begin = GUICtrlCreateButton("Start Click", 16, 16, 137, 33) $btn_pause = GUICtrlCreateButton("Pause / Resume", 184, 16, 137, 33) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 ;~ HotKeySet("{f1}", "begin") ;~ Sleep(50) ;~ HotKeySet("{f3}", "pause") ;~ Sleep(50) $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $btn_begin begin() Case $btn_pause pause() EndSwitch WEnd Func begin() ;~ For $i = 1 To 10 ;~ While 1 <<<<<<<<<<<<<< not sure why you think you need so many While loops MsgBox($MB_SYSTEMMODAL, "Title", "This message box will timeout after 10 seconds or select the OK button.", 10) ;~ Sleep(500) <<<<<<<<<<<<<<<<<< Unnecessary ;~ ExitLoop ;~ WEnd ;~ Next ;~ Sleep(50) <<<<<<<<<<<<<<< or so many sleep statements. EndFunc ;==>begin Func pause() $g_bPaused = Not $g_bPaused While $g_bPaused ToolTip('Script is Paused"', 500, 500) $nMsg = GUIGetMsg() Switch $nMsg Case $btn_pause $g_bPaused = Not $g_bPaused EndSwitch Sleep(10) WEnd ToolTip('Script is not Paused"', 500, 500) EndFunc ;==>pause aa2zz6 1 If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
hoangakavn Posted April 20, 2018 Author Share Posted April 20, 2018 (edited) thank you for help me, but this not work if use while end, because this code is example == main code expandcollapse popup;CreatGui.... #EndRegion ### END Koda GUI section ### While 1 HotKeySet("{f1}","Fam2NoxAdv") Sleep(50) HotKeySet("{f3}","pause") Sleep(50) HotKeySet("{f2}","thoat") Sleep(50) $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $btn_autopanel autopanel() Case $btn_fix1 fix1() Case $btn_fam_2nox_adv Fam2NoxAdv() Case $btn_thoat thoat() Case $btn_pause pause() EndSwitch WEnd ;fam 2 acc xem adv Func Fam2NoxAdv() Global $g_bPaused = False For $i=1 to 1000 Sleep(3000) ControlClick($hWnd,"","","left",2,308,12+30) Sleep(500) ;neu full thi ban Do $color = PixelGetColor(465,286) $color1 = PixelGetColor(301,287) if $color = 0x9FEF53 or $color1 = 0x9EEE52 Then bando() Else ControlClick($hWnd,"","","left",2,308,12+30) Sleep(50) EndIf While 1 $color = PixelGetColor(662,96) $color1 = PixelGetColor(645,102) if $color = 0x58A16C or $color1 = 0xAFD2B9 Then ControlClick($hWnd,"","","left",2,332,79) Sleep(100) ExitLoop EndIf WEnd v.v... Next Sleep(50) EndFunc ;pause script Func pause() $g_bPaused = Not $g_bPaused While $g_bPaused Sleep(100) ToolTip('Script is pause"', 500, 500) WEnd EndFunc when i click button pause not work but when i press hotkey f3 then pause script, but i want when i click button pause func Fam2NoxAdv() is pause Edited April 20, 2018 by hoangakavn Link to comment Share on other sites More sharing options...
hoangakavn Posted April 20, 2018 Author Share Posted April 20, 2018 i want stop func begin() with button pause, this loop is example Func begin() Global $g_bPaused = False For $i=1 to 10 while 1 MsgBox($MB_SYSTEMMODAL, "Title", "This message box will timeout after 10 seconds or select the OK button.", 10) Sleep(500) ExitLoop WEnd Next Sleep(50) EndFunc Link to comment Share on other sites More sharing options...
BrewManNH Posted April 20, 2018 Share Posted April 20, 2018 No idea what you're asking now, that's not the same question you asked at first. Also, did you read the comments I put into the script I posted? Don't declare Global variables inside a function, move your HokeySets outside the functions/loops too, no reason for them to be in there. What is your obsession with using Sleep statements? If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
hoangakavn Posted April 21, 2018 Author Share Posted April 21, 2018 (edited) if i press f3 func begin() is pause, but when i click button pause not work, why?. this is example expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> Global $g_bPaused = False HotKeySet("{f1}", "begin") HotKeySet("{f3}", "pause") #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 336, 72, 192, 124) $btn_begin = GUICtrlCreateButton("Start Click", 16, 16, 137, 33) $btn_pause = GUICtrlCreateButton("Pause / Resume", 184, 16, 137, 33) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $btn_begin begin() Case $btn_pause ; if i press f3 func begin() is pause, but when i click button pause not work, why? pause() EndSwitch WEnd ;Example Func begin() ; loop is example, i need : when i click button btn_pause then func begin() will pause ;my code $color = PixelGetColor(465,286) $color1 = PixelGetColor(301,287) if $color30 = 0x9FEF53 or $color31 = 0x9EEE52 Then bando() Else ControlClick($hWnd,"","","left",2,308,12+30) Sleep(50) EndIf While 1 $color = PixelGetColor(662,96) $color1 = PixelGetColor(645,102) if $color = 0x58A16C or $color1 = 0xAFD2B9 Then ControlClick($hWnd,"","","left",2,332,79) Sleep(100) ExitLoop EndIf WEnd Sleep(1500) ControlClick($hWnd,"","","left",2,577,349) Sleep(1000) $color = PixelGetColor(378,350) $color1 = PixelGetColor(381,354) if $color = 0x9FEF53 or $color1 = 0x9AEA4E Then xemquangcao() Else ControlClick($hWnd,"","","left",2,484,170) Sleep(1000) EndIf Next Sleep(50) EndFunc ;you can test example, this same my code ; loop is example, i need : when i click button btn_pause then func begin() will pause ;For $i = 1 To 10 ;While 1 ; MsgBox($MB_SYSTEMMODAL, "Title", "This message box will timeout after 10 seconds or select the OK button.", 10) ; Sleep(500) ;WEnd Func pause() $g_bPaused = Not $g_bPaused While $g_bPaused ToolTip('Script is Paused"', 500, 500) $nMsg = GUIGetMsg() Switch $nMsg Case $btn_pause $g_bPaused = Not $g_bPaused EndSwitch Sleep(10) WEnd ToolTip('Script is not Paused"', 500, 500) EndFunc ;==>pause Edited April 21, 2018 by hoangakavn Link to comment Share on other sites More sharing options...
aa2zz6 Posted April 21, 2018 Share Posted April 21, 2018 (edited) I assume the issue is tied to the message box. Maybe swap it out for a ConsoleWrite("...") for testing purposes and it should work fine While 1 ConsoleWrite("test") ;MsgBox($MB_SYSTEMMODAL, "Title", "This message box will timeout after 10 seconds or select the OK button.", 10) Sleep(500) WEnd Edited April 21, 2018 by aa2zz6 Link to comment Share on other sites More sharing options...
JohnOne Posted April 21, 2018 Share Posted April 21, 2018 AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Developers Jos Posted April 21, 2018 Developers Share Posted April 21, 2018 @hoangakavn, Please don't create new topics for the same question and simply stick to the original! Merged, Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
hoangakavn Posted April 21, 2018 Author Share Posted April 21, 2018 (edited) i want when i click button pause then func Fam2NoxAdv() is pause Func Fam2NoxAdv() Can you edit script for me? Edited April 21, 2018 by hoangakavn Link to comment Share on other sites More sharing options...
Developers Jos Posted April 21, 2018 Developers Share Posted April 21, 2018 (edited) I understand what you want and told you something else which I hope you understood too. As to your question: I fail to understand why you ask us to update your script which we are not able to run anyways as you only posted a portion! Simply read the helpfile topic "GUI Reference - OnEvent Mode:" and use GUICtrlSetOnEvent() and figure it out yourself. Jos Edited April 21, 2018 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
hoangakavn Posted April 21, 2018 Author Share Posted April 21, 2018 1 hour ago, Jos said: @hoangakavn, Please don't create new topics for the same question and simply stick to the original! Merged, Jos i'm so sorry, i'm newbie, thank you Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now