exevan Posted May 3, 2014 Share Posted May 3, 2014 #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 310, 437, 345, 194) $Button2 = GUICtrlCreateButton("Pauza", 80, 128, 75, 25, $WS_GROUP) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $fPaused = False HotKeySet("{p}","_Pause") Func _Pause() $fPaused = Not $fPaused if not $fPaused then Tooltip("Program is running",0,0) GUICtrlSetData($Button2,"Pause") else Tooltip("Program is pause.",0,0) GUICtrlSetData($Button2,"Run") endif While $fPaused Sleep(100) WEnd EndFunc While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button2 _Pause() EndSwitch WEnd Look for this script. If i click key 'p' all works (look tooltip). But why it doesn't works with button? Link to comment Share on other sites More sharing options...
JohnOne Posted May 3, 2014 Share Posted May 3, 2014 Button works to pause, but not unpause, because while it's paused gui is not being polled by guigetmsg() 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...
DatMCEyeBall Posted May 3, 2014 Share Posted May 3, 2014 You can change the while loop in the _Pause() function to look like this: While $fPaused If GuiGetMsg() = $Button2 Then _Pause() EndIf WEnd "Just be fred, all we gotta do, just be fred." -Vocaliod "That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha @tabhooked Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation Link to comment Share on other sites More sharing options...
exevan Posted May 3, 2014 Author Share Posted May 3, 2014 Ok it works, but now if i put a exit button and its looks like that: expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 310, 437, 345, 194) $Button2 = GUICtrlCreateButton("Pauza", 80, 128, 75, 25, $WS_GROUP) $Button3 = GUICtrlCreateButton("Exit", 80, 50, 75, 25, $WS_GROUP) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $fPaused = False HotKeySet("{p}","_Pause") Func _Pause() $fPaused = Not $fPaused if not $fPaused then Tooltip("Program is running",0,0) GUICtrlSetData($Button2,"Pause") else Tooltip("Program is pause.",0,0) GUICtrlSetData($Button2,"Run") endif While $fPaused If GuiGetMsg() = $Button2 Then _Pause() EndIf WEnd EndFunc Func _Exit() Exit EndFunc While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button2 _Pause() Case $Button3 _Exit() EndSwitch WEnd If program is paused i can't click the exit button. But when the program is running already exit button work;/ Link to comment Share on other sites More sharing options...
Starstar Posted May 3, 2014 Share Posted May 3, 2014 (edited) expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 310, 437, 345, 194) $Button2 = GUICtrlCreateButton("Pauza", 80, 128, 75, 25, $WS_GROUP) $Button3 = GUICtrlCreateButton("Exit", 80, 50, 75, 25, $WS_GROUP) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $fPaused = False HotKeySet("{p}","_Pause") HotKeySet("{e}","_Exit") Func _Pause() $fPaused = Not $fPaused if not $fPaused then Tooltip("Program is running",0,0) GUICtrlSetData($Button2,"Pause") else Tooltip("Program is pause.",0,0) GUICtrlSetData($Button2,"Run") endif While $fPaused If GuiGetMsg() = $Button2 Then _Pause() EndIf WEnd EndFunc Func _Exit() Exit EndFunc While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button2 _Pause() Case $Button3 _Exit() EndSwitch WEnd Press "e" to Exit script..............Tested in win 7 Edit;; While your script is paused or not script will be closed when you press "e". Edited May 3, 2014 by Starstar Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once." Link to comment Share on other sites More sharing options...
exevan Posted May 3, 2014 Author Share Posted May 3, 2014 I know that.. I want to use in my script the button. Link to comment Share on other sites More sharing options...
JohnOne Posted May 3, 2014 Share Posted May 3, 2014 Just do the same with $GUI_EVENT_CLOSE as DatMCEyeBall showed with $button. 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...
exevan Posted May 3, 2014 Author Share Posted May 3, 2014 Func _Exit() if GuiGetMsg() = $Button3 Then Exit endif EndFunc doesn't work. I don't know how to do that;/ Link to comment Share on other sites More sharing options...
JohnOne Posted May 3, 2014 Share Posted May 3, 2014 Show implemented ruunnable code. 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...
exevan Posted May 3, 2014 Author Share Posted May 3, 2014 expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 310, 437, 345, 194) $Button2 = GUICtrlCreateButton("Pauza", 80, 128, 75, 25, $WS_GROUP) $Button3 = GUICtrlCreateButton("Exit", 80, 70, 75, 25, $WS_GROUP) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $fPaused = False HotKeySet("{p}","_Pause") Func _Pause() $fPaused = Not $fPaused if not $fPaused then Tooltip("Program is running",0,0) GUICtrlSetData($Button2,"Pause") else Tooltip("Program is pause.",0,0) GUICtrlSetData($Button2,"Run") endif While $fPaused If GuiGetMsg() = $Button2 Then _Pause() EndIf WEnd EndFunc Func _Exit() if GuiGetMsg() = $Button3 Then Exit endif EndFunc While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button2 _Pause() Case $Button3 _Exit() EndSwitch WEnd Link to comment Share on other sites More sharing options...
JohnOne Posted May 3, 2014 Share Posted May 3, 2014 You need to check for GUI_EVENT_CLOSE in while loop in your pause function as you do with $button like DatMCEyeBall showed you. 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...
exevan Posted May 3, 2014 Author Share Posted May 3, 2014 expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 310, 437, 345, 194) $Button2 = GUICtrlCreateButton("Pauza", 80, 128, 75, 25, $WS_GROUP) $Button3 = GUICtrlCreateButton("Exit", 80, 70, 75, 25, $WS_GROUP) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $fPaused = False HotKeySet("{p}","_Pause") Func _Pause() $fPaused = Not $fPaused if not $fPaused then Tooltip("Program is running",0,0) GUICtrlSetData($Button2,"Pause") else Tooltip("Program is pause.",0,0) GUICtrlSetData($Button2,"Run") endif While $fPaused If GuiGetMsg() = $Button2 Then _Pause() endif if GuiGetMsg() = $Button3 Then _Exit() endif WEnd EndFunc Func _Exit() Exit EndFunc While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $Button2 _Pause() Case $Button3 _Exit() EndSwitch WEnd I don't know i understand you but i do this and work BUT when i clicked many times in one second the script is lagged;/ Link to comment Share on other sites More sharing options...
JohnOne Posted May 3, 2014 Share Posted May 3, 2014 expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 310, 437, 345, 194) $Button2 = GUICtrlCreateButton("Pauza", 80, 128, 75, 25, $WS_GROUP) $Button3 = GUICtrlCreateButton("Exit", 80, 70, 75, 25, $WS_GROUP) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $fPaused = False HotKeySet("{p}", "_Pause") Func _Pause() $fPaused = Not $fPaused If Not $fPaused Then ToolTip("Program is running", 0, 0) GUICtrlSetData($Button2, "Pause") Else ToolTip("Program is pause.", 0, 0) GUICtrlSetData($Button2, "Run") EndIf While $fPaused Switch GUIGetMsg() Case $Button2 _Pause() Case $Button3 _Exit() EndSwitch WEnd EndFunc ;==>_Pause Func _Exit() Exit EndFunc ;==>_Exit While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $Button2 _Pause() Case $Button3 _Exit() EndSwitch WEnd DatMCEyeBall 1 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...
exevan Posted May 3, 2014 Author Share Posted May 3, 2014 Ok thank you. I have next problem ;/ expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 310, 437, 345, 194) $Button2 = GUICtrlCreateButton("Pauza", 80, 128, 75, 25, $WS_GROUP) $Button3 = GUICtrlCreateButton("Exit", 80, 70, 75, 25, $WS_GROUP) $Button4 = GUICtrlCreateButton("Count", 80, 95, 75, 25, $WS_GROUP) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $i Global $fPaused = False HotKeySet("{p}", "_Pause") Func _Pause() $fPaused = Not $fPaused If Not $fPaused Then ToolTip("Program is running", 0, 0) GUICtrlSetData($Button2, "Pause") Else ToolTip("Program is pause.", 0, 0) GUICtrlSetData($Button2, "Run") EndIf While $fPaused Switch GUIGetMsg() Case $Button2 _Pause() Case $Button3 _Exit() Case $Button4 ToolTip("You can't run script while program is paused",0,0) EndSwitch WEnd EndFunc ;==>_Pause Func _Count() While 1 $i = $i+1 ToolTip("Time: "&$i,0,0) sleep(1000) wend EndFunc Func _Exit() Exit EndFunc ;==>_Exit While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $Button2 _Pause() Case $Button3 _Exit() Case $Button4 _Count() EndSwitch WEnd when i add next function and click "count" i can't pause the script and exit. Any ideas? Because i don't have any idea. I tried all ;/ Link to comment Share on other sites More sharing options...
JohnOne Posted May 3, 2014 Share Posted May 3, 2014 If you're going to make a claim that you "tried all" you should post everything you tried. 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...
exevan Posted May 3, 2014 Author Share Posted May 3, 2014 I added variable: Global $fCount = False and do very similar what i have in pause function expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 310, 437, 345, 194) $Button2 = GUICtrlCreateButton("Pauza", 80, 128, 75, 25, $WS_GROUP) $Button3 = GUICtrlCreateButton("Exit", 80, 70, 75, 25, $WS_GROUP) $Button4 = GUICtrlCreateButton("Count", 80, 95, 75, 25, $WS_GROUP) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $i Global $fPaused = False Global $fCount = False HotKeySet("{p}", "_Pause") Func _Pause() $fPaused = Not $fPaused If Not $fPaused Then ToolTip("Program is running", 0, 0) GUICtrlSetData($Button2, "Pause") Else ToolTip("Program is pause.", 0, 0) GUICtrlSetData($Button2, "Run") EndIf While $fPaused Switch GUIGetMsg() Case $Button2 _Pause() Case $Button3 _Exit() Case $Button4 ToolTip("You can't run script while program is paused",0,0) EndSwitch WEnd EndFunc ;==>_Pause Func _Count() $fCount = not $fCount if $fCount then While 1 $i = $i+1 ToolTip("Time: "&$i,0,0) sleep(1000) wend else tooltip("??",0,0) endif While $fCount Switch GUIGetMsg() Case $Button2 _Pause() Case $Button3 _Exit() Case $Button4 _Count() EndSwitch WEnd EndFunc Func _Exit() Exit EndFunc ;==>_Exit While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $Button2 _Pause() Case $Button3 _Exit() Case $Button4 _Count() EndSwitch WEnd i _Pause it works but doesn't in _Count Link to comment Share on other sites More sharing options...
JohnOne Posted May 3, 2014 Share Posted May 3, 2014 You'd need to once again poll guigetmsg in your if $fCount then while loop. 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...
BrewManNH Posted May 3, 2014 Share Posted May 3, 2014 Do NOT use that like that or eventually your script will crash. You're calling the _Pause function from within the _Pause function, you're going to get a recursion error eventually if you use this for any length of time.You should be returning from all your functions and use one While loop, not a separate one in each function, not only is it a bitch to troubleshoot problems that way, it's not necessary if you write the code to deal with things like this. Check out the GUIRegisterMsg demo I have linked in my signature, you can use one loop and still action buttons without needing to use the terrible code I see in this thread. DatMCEyeBall 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...
exevan Posted May 3, 2014 Author Share Posted May 3, 2014 But i want to do, when the some function is running already i want to stop this. Link to comment Share on other sites More sharing options...
JohnOne Posted May 3, 2014 Share Posted May 3, 2014 In your _pause function while loops, swap _Pause() for $fPaused = Not $fPaused. 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...
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