Deathboy Posted April 26, 2010 Share Posted April 26, 2010 Well the thing is I got a script witch gonna check something every 30min So I put a sleep command in for 30min. But if I wanna abort the waiting and do it manually I can't because the script won't respond because its sleeping Any idea how to make it work? Link to comment Share on other sites More sharing options...
Thornhunt Posted April 26, 2010 Share Posted April 26, 2010 Well the thing is I got a script witch gonna check something every 30minSo I put a sleep command in for 30min.But if I wanna abort the waiting and do it manually I can't because the script won't respond because its sleepingAny idea how to make it work?general help and supportthis belongs in that section i beliveand you could do this with hotkeys Budweiser + room = warm beerwarm beer + fridge = too long!warm beer + CO2 fire extinguisher = Perfect![quote]Protect the easly offended ... BAN EVERYTHING[/quote]^^ hmm works for me :D Link to comment Share on other sites More sharing options...
JRowe Posted April 26, 2010 Share Posted April 26, 2010 Pretty simple. Create a function called _Pause() that does something like this: Func _Pause() Local $a = TimerInit() Local $b = 0 While $b < 30000 ; Or however long you want it to sleep $b = TimerDiff($a) Sleep(50) ; Sleeps in 50 ms increments, so the CPU doesn't get hogged Wend [center]However, like ninjas, cyber warriors operate in silence.AutoIt Chat Engine (+Chatbot) , Link Grammar for AutoIt , Simple Speech RecognitionArtificial Neural Networks UDF , Bayesian Networks UDF , Pattern Matching UDFTransparent PNG GUI Elements , Au3Irrlicht 2Advanced Mouse Events MonitorGrammar Database GeneratorTransitions & Tweening UDFPoker Hand Evaluator[/center] Link to comment Share on other sites More sharing options...
Deathboy Posted April 26, 2010 Author Share Posted April 26, 2010 Pretty simple. Create a function called _Pause() that does something like this: Func _Pause() Local $a = TimerInit() Local $b = 0 While $b < 30000 ; Or however long you want it to sleep $b = TimerDiff($a) Sleep(50) ; Sleeps in 50 ms increments, so the CPU doesn't get hogged Wend Doesn't seem to work :/ still the same that it won't respond:/ But thanks for the reply Link to comment Share on other sites More sharing options...
JRowe Posted April 26, 2010 Share Posted April 26, 2010 You'll have to add code that does something. Use HotKeySet() to call the function you want to execute manually. In the future, when you post help and support questions, please include your code (in [autoit] tags.) That way, we can help you more, because we can see exactly what the problems are. Hope this helps [center]However, like ninjas, cyber warriors operate in silence.AutoIt Chat Engine (+Chatbot) , Link Grammar for AutoIt , Simple Speech RecognitionArtificial Neural Networks UDF , Bayesian Networks UDF , Pattern Matching UDFTransparent PNG GUI Elements , Au3Irrlicht 2Advanced Mouse Events MonitorGrammar Database GeneratorTransitions & Tweening UDFPoker Hand Evaluator[/center] Link to comment Share on other sites More sharing options...
Deathboy Posted April 26, 2010 Author Share Posted April 26, 2010 (edited) You'll have to add code that does something. Use HotKeySet() to call the function you want to execute manually. In the future, when you post help and support questions, please include your code (in [autoit] tags.) That way, we can help you more, because we can see exactly what the problems are. Hope this helps okay, I'm a very shitty scripter:P but took a little part from the code just to show what I mean. #include <GUIConstantsEx.au3> Opt("GUIOnEventMode", 1) $mainwindow = GUICreate("Posten sporing", 250, 150) GUISetOnEvent($GUI_EVENT_CLOSE, "Quit") GUISetState(@SW_SHOW) $updatebutton = GUICtrlCreateButton("AutoCheck", 124, 110, 60, 25) GUICtrlSetOnEvent($updatebutton, "autocheck") Func autocheck() while 1 sleep(5000) MsgBox("lol","hi", ":D", "") wend EndFunc Func Quit() Exit EndFunc while 1 sleep(100000) wend If i push autocheck button in the GUI I can't close it with the X in top right corner. Can close it if I don't push the autocheck button. Your code didn't work either for it JRowe :/ Edited April 26, 2010 by Deathboy Link to comment Share on other sites More sharing options...
JRowe Posted April 26, 2010 Share Posted April 26, 2010 While it's sleeping for 100000 ms, it does nothing. Instead of one gigantic sleep during which the script can't do anything, you want the script to test whether or not it should be doing something. Sleep literally stops the script for however many ms you specify. Use TimerInit to set a timestamp and timerdiff to test how long its been since the timestamp, and use a smaller sleep (10-100 ms.) For example: #include <GUIConstantsEx.au3> Global $mainwindow = GUICreate("Posten sporing", 250, 150) Global $updatebutton = GUICtrlCreateButton("AutoCheck", 124, 110, 60, 25) GUISetState(@SW_SHOW) Global $a = TimerInit() Global $b = 0 While 1 $b = TimerDiff($a) If $b > 3000 Then $a = TimerInit() ; reset the timer _AutoCheck() EndIf $msg = GUIGetMsg() If $msg = $updatebutton Then $a = TimerInit() ; reset the timer after manual activation _AutoCheck("Called manually from $updatebutton") EndIf If $msg = $GUI_EVENT_CLOSE Then Quit() EndIf Sleep(10) ; small sleeps so it doesn't hog CPU, but remains responsive. WEnd Func _AutoCheck($s_Message = "This is an autocheck.") MsgBox(0, $s_Message, "Checking!") EndFunc ;==>_AutoCheck Func Quit() Exit EndFunc ;==>Quit That keeps it responsive. I'd recommend not using onevent mode for something like that. Also, use Select/Case if you're going to have more than one GUI event, so that the code is easier to understand and add to. [center]However, like ninjas, cyber warriors operate in silence.AutoIt Chat Engine (+Chatbot) , Link Grammar for AutoIt , Simple Speech RecognitionArtificial Neural Networks UDF , Bayesian Networks UDF , Pattern Matching UDFTransparent PNG GUI Elements , Au3Irrlicht 2Advanced Mouse Events MonitorGrammar Database GeneratorTransitions & Tweening UDFPoker Hand Evaluator[/center] Link to comment Share on other sites More sharing options...
Deathboy Posted April 26, 2010 Author Share Posted April 26, 2010 While it's sleeping for 100000 ms, it does nothing. Instead of one gigantic sleep during which the script can't do anything, you want the script to test whether or not it should be doing something. Sleep literally stops the script for however many ms you specify. Use TimerInit to set a timestamp and timerdiff to test how long its been since the timestamp, and use a smaller sleep (10-100 ms.) For example: #include <GUIConstantsEx.au3> Global $mainwindow = GUICreate("Posten sporing", 250, 150) Global $updatebutton = GUICtrlCreateButton("AutoCheck", 124, 110, 60, 25) GUISetState(@SW_SHOW) Global $a = TimerInit() Global $b = 0 While 1 $b = TimerDiff($a) If $b > 3000 Then $a = TimerInit() ; reset the timer _AutoCheck() EndIf $msg = GUIGetMsg() If $msg = $updatebutton Then $a = TimerInit() ; reset the timer after manual activation _AutoCheck("Called manually from $updatebutton") EndIf If $msg = $GUI_EVENT_CLOSE Then Quit() EndIf Sleep(10) ; small sleeps so it doesn't hog CPU, but remains responsive. WEnd Func _AutoCheck($s_Message = "This is an autocheck.") MsgBox(0, $s_Message, "Checking!") EndFunc ;==>_AutoCheck Func Quit() Exit EndFunc ;==>Quit That keeps it responsive. I'd recommend not using onevent mode for something like that. Also, use Select/Case if you're going to have more than one GUI event, so that the code is easier to understand and add to. Sorry to nag again^^ but now it starts the autochecking as soon as I open the program. Its not supposed to do so before the Autocheck button is pushed^^ Link to comment Share on other sites More sharing options...
MHz Posted April 27, 2010 Share Posted April 27, 2010 A change to the script by JRowe with autocheck using a flag variable to only use autocheck if the autocheck button has been clicked. #include <GUIConstantsEx.au3> Global $mainwindow = GUICreate("Posten sporing", 250, 150) Global $updatebutton = GUICtrlCreateButton("AutoCheck", 124, 110, 60, 25) GUISetState(@SW_SHOW) Global $handle_timer ; handle returned from TimerInit() Global $autocheck = False ; boolean value for AutoCheck button While 1 $msg = GUIGetMsg() If $msg = $updatebutton Then $autocheck = True ; activate autocheck $handle_timer = TimerInit() ; reset the timer _AutoCheck("Called manually from $updatebutton") ElseIf $msg = $GUI_EVENT_CLOSE Then Quit() EndIf If $autocheck Then If TimerDiff($handle_timer) > 5000 Then $handle_timer = TimerInit() ; reset the timer _AutoCheck() EndIf EndIf WEnd Func _AutoCheck($s_Message = "This is an autocheck.") MsgBox(0, $s_Message, "Checking!", 1) EndFunc ;==>_AutoCheck Func Quit() Exit EndFunc ;==>Quit You could also use AdlibRegister() if suitable. Example of AdlibRegister #include <GUIConstantsEx.au3> Global $mainwindow = GUICreate("Posten sporing", 250, 150) Global $updatebutton = GUICtrlCreateButton("AutoCheck", 124, 110, 60, 25) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() If $msg = $updatebutton Then AdlibRegister('_AutoCheck', 3000) ; activate autocheck ElseIf $msg = $GUI_EVENT_CLOSE Then Quit() EndIf WEnd Func _AutoCheck() MsgBox(0, @ScriptName, "Checking!", 1) EndFunc Func Quit() Exit EndFunc Link to comment Share on other sites More sharing options...
Deathboy Posted April 27, 2010 Author Share Posted April 27, 2010 A change to the script by JRowe with autocheck using a flag variable to only use autocheck if the autocheck button has been clicked. #include <GUIConstantsEx.au3> Global $mainwindow = GUICreate("Posten sporing", 250, 150) Global $updatebutton = GUICtrlCreateButton("AutoCheck", 124, 110, 60, 25) GUISetState(@SW_SHOW) Global $handle_timer ; handle returned from TimerInit() Global $autocheck = False ; boolean value for AutoCheck button While 1 $msg = GUIGetMsg() If $msg = $updatebutton Then $autocheck = True ; activate autocheck $handle_timer = TimerInit() ; reset the timer _AutoCheck("Called manually from $updatebutton") ElseIf $msg = $GUI_EVENT_CLOSE Then Quit() EndIf If $autocheck Then If TimerDiff($handle_timer) > 5000 Then $handle_timer = TimerInit() ; reset the timer _AutoCheck() EndIf EndIf WEnd Func _AutoCheck($s_Message = "This is an autocheck.") MsgBox(0, $s_Message, "Checking!", 1) EndFunc ;==>_AutoCheck Func Quit() Exit EndFunc ;==>Quit You could also use AdlibRegister() if suitable. Example of AdlibRegister #include <GUIConstantsEx.au3> Global $mainwindow = GUICreate("Posten sporing", 250, 150) Global $updatebutton = GUICtrlCreateButton("AutoCheck", 124, 110, 60, 25) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() If $msg = $updatebutton Then AdlibRegister('_AutoCheck', 3000) ; activate autocheck ElseIf $msg = $GUI_EVENT_CLOSE Then Quit() EndIf WEnd Func _AutoCheck() MsgBox(0, @ScriptName, "Checking!", 1) EndFunc Func Quit() Exit EndFunc Tnx alot MHz the first script you provided was just what I was looking for Link to comment Share on other sites More sharing options...
MHz Posted April 28, 2010 Share Posted April 28, 2010 Your welcome. I did minor changes to the good example script by JRowe so JRowe deserves most credit and thanks. Thanks JRowe. Link to comment Share on other sites More sharing options...
Deathboy Posted April 28, 2010 Author Share Posted April 28, 2010 Your welcome. I did minor changes to the good example script by JRowe so JRowe deserves most credit and thanks. Thanks JRowe. Thanks JRowe too couln't have done it without you two Link to comment Share on other sites More sharing options...
JRowe Posted April 28, 2010 Share Posted April 28, 2010 Very welcome, I'm glad it helped you [center]However, like ninjas, cyber warriors operate in silence.AutoIt Chat Engine (+Chatbot) , Link Grammar for AutoIt , Simple Speech RecognitionArtificial Neural Networks UDF , Bayesian Networks UDF , Pattern Matching UDFTransparent PNG GUI Elements , Au3Irrlicht 2Advanced Mouse Events MonitorGrammar Database GeneratorTransitions & Tweening UDFPoker Hand Evaluator[/center] 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