Search the Community
Showing results for tags 'Sleep'.
-
I have a script that reads the last 7 lines of an active log file. By active I mean that the file is being written while the script runs. How can I make the script to 1- keep reading the last 7 lines till a specific text appears. 2- Once the specific text appears, then get out of the loop and proceed to other tasks Thank You
-
TL;DR: Anyway to bypass built in sleep on TrayGetMsg() and GUIGetMsg() ? I'm currently working on a project that does some heavy array/ GDI+ processing, which depending what I have it do can take between 4s - 1min. During this time, I'd like to have the Tray icon (mainly, possibly also the GUI) for the program be responsive, so that if someone wanted to change actions or exit the script during this, they can without closing the process. Currently I have my TrayGetMsg and GUIGetMsg captures in my main program loop, working great, and once I go into the array/ GDI+ functions I tried switching it to an AdlibRegister call, unregistering it once completed. The problem with this is that it's adding ~10-20% more time into those functions, which I'd like to avoid. As I understand it, and from the helpfile: "This function automatically idles the CPU when required so that it can be safely used in tight loops without hogging all the CPU." From what I've read/ seen/ tested, this adds a 10ms sleep into the calls. I would rather avoid that sleep all together. The array/ GDI+ function that I'm doing peg the CPU at 100% (for its core) anyways, so that's not a concern of mine. My only concern for this is speed (and having things be responsive to other actions). Here's an example: Local $iBlockSize = 20, $iWidth = 1920, $iHeight = 1080, $aBigArray[$iWidth * $iHeight], $iPercentDone, $sLastMsg Local $aSmallerArray[Int(Ceiling($iWidth / $iBlockSize)) * Int(Ceiling($iHeight / $iBlockSize))] Local $sAdlib[] = ["Registered: ", "UnRegistered: ", "Registered to _FakeTray: "], $timer, $iIndexLength = UBound($aBigArray) Local $ixBlocks = Int(Ceiling($iWidth / $iBlockSize)), $iBlockIndex, $iBlockX, $iBlockY For $j = 0 To 2 If $j = 0 Then AdlibRegister("_CheckTray", 100) ElseIf $j = 1 Then AdlibUnRegister("_CheckTray") ElseIf $j = 2 Then AdlibRegister("_FakeTray", 100) EndIf $timer = TimerInit() For $i = 0 To $iIndexLength - 1 ; Loop through $aBigArray $aBigArray[$i] = Random(1, 10, 1) $iPercentDone = Floor(($i / $iIndexLength * 100)) ; Hopefully quick maths to get progress If $sLastMsg <> "We are " & $iPercentDone & "% done" Then ; Check if we're on a new percent $sLastMsg = "We are " & $iPercentDone & "% done" ; If so, update the msg ToolTip($sLastMsg, 0, 0) ; And display the current progress EndIf $y = Floor($i / $iWidth) ; Convert index to Y coordinate $x = Floor($i - ($y * $iWidth)) ; Convert index to X coordinate $iBlockX = Floor($x / $iBlockSize) ; Convert X coord to xBlock coord $iBlockY = Floor($y / $iBlockSize) ; Convert Y coord to yBlock coord $iBlockIndex = Int($iBlockX + ($iBlockY * $ixBlocks)) ; Convert into a blockIndex ;~ If Mod($i, 10000) = 0 Then ;~ ConsoleWrite($iBlockIndex & " - " & $i & @CRLF) ;~ EndIf $aSmallerArray[$iBlockIndex] += Int($aBigArray[$i]) ; Add into $aSmallerArray Next ConsoleWrite("Time to run with Adlib" & $sAdlib[$j] & TimerDiff($timer) & @CRLF) Next Func _CheckTray() Switch TrayGetMsg() Case "Meow" Return Case "Woof" Return EndSwitch EndFunc ;==>_CheckTray Func _FakeTray() Local $sMeow = "Oink" Switch $sMeow Case "Meow" Return Case "Woof" Return EndSwitch EndFunc ;==>_FakeTray Exit On my system, this takes ~1 minute to run, output: Time to run with AdlibRegistered: 19649.335 Time to run with AdlibUnRegistered: 16264.4124 Time to run with AdlibRegistered to _FakeTray: 16860.1283 >Exit code: 0 Time: 53.92 As you can see, it's ~20.8% faster without the Adlib check, and ~16.5% faster using a (hopefully) reproduction of TrayGetMsg() without the built in sleep. These timings vary, but it's consistently much faster without the TrayGetMsg() sleep (unless it's just that slow). I've used the OnEventModes, and those also slow down performance, more so than just using the GetMsgs, so those are out (but effective, and pretty easy to use).
- 6 replies
-
- traygetmsg
- guigetmsg
-
(and 1 more)
Tagged with:
-
I have script Like This : Opt("TrayAutoPause",0) $var = Ping("www.google.com") If not @error Then WinActivate ( "testapp") ControlClick ( "testapp", "", "[Savetest]") ControlSend ( " :: Gujarat TPDS - eFPS :: Version - 2.2.0.0 - [eFPS Bill]", "", "[NAME:btnSavebyFP]", "{enter}") WinWait(":: Aadhar/EID/Verification Number Entry ::") ControlClick(":: Aadhar/EID/Verification Number Entry ::", "", "[NAME:btnNext]") If WinExists ("Aadhar : Length Check") Then ControlClick("Aadhar : Length Check", "", "[CLASS:Button; INSTANCE:1]") ControlSend(":: Aadhar/EID/Verification Number Entry ::", "", "[NAME:txtAadharNumber]", "{backspace}") ControlSend(":: Aadhar/EID/Verification Number Entry ::", "", "[NAME:txtAadharNumber]", "^v") ControlClick(":: Aadhar/EID/Verification Number Entry ::", "", "[NAME:btnNext]") WinWait(" :: Barcoded Ration Card Members - Biometric Verification/Check Utility ::") ControlSend("[Class:WindowsForms10.Window.8.app.0.378734a]", "", "[NAME:PictureBox2]", "{tab} {enter}") Sleep(5600) RunWait("rasdial /disconnect", "", @SW_HIDE) ; Stop connect from start RunWait("rasdial Internet", "", @SW_HIDE) ; Connect again Exit EndIf WinWait(" :: Barcoded Ration Card Members - Biometric Verification/Check Utility ::", "", 1) ControlSend("[Class:WindowsForms10.Window.8.app.0.378734a]", "", "[NAME:PictureBox2]", "{tab} {enter}") Sleep(5600) RunWait("rasdial /disconnect", "", @SW_HIDE) ; Stop connect from start RunWait("rasdial Internet", "", @SW_HIDE) ; Connect again Exit Else #include <MsgBoxConstants.au3> MsgBox($MB_TOPMOST, "Connection Status", "Internet is not Connected") Exit Endif
-
How can i add sleep command using internet speed. If my internet speed is 40-50Kbps then sleep for 5 seconds, If my internet speed is 30-40Kbps then sleep for 4 seconds, If my internet speed is 20-30Kbps then sleep for 3 seconds. *Sleep command used bitween my costom script, Example, RunWait("rasdial /disconnect", "", @SW_HIDE) ; Stop connect from start Sleep(5000) RunWait("rasdial Internet", "", @SW_HIDE) ; Connect again
-
Hi there, I did a short script to simulate mouse click when pixel change is detected on a small section of the screen. I recorded the screen many times to see the accuracy of the script and it seems though response time varies widely. Here's the script $checksum = pixelchecksum (400,250, 402,252) While $checksum = pixelchecksum (400,250, 402,252) Sleep (50) Wend Sleep (300) Mouseclick("left", 450,300, 1, 0) Counting from the pixel change to the mouse click, i get response times anywhere between 370ms and 550ms. I've tried running au3 and exe, changed sleep times but never gotten an accurate response time based on the script. Any ideas why?
- 6 replies
-
- pixelchecksum
- mouseclick
-
(and 2 more)
Tagged with:
-
Update 2017-04-21: Added a timeout My previous attempt of checking that the function is valid was not working. Added a 1 time function call before entering the While loop to test the function. Now sets error to $SLEEP_UNTIL_INVALID_CALL if the function supplied is does not exist or invalid arguments supplied Added an @Error value $SLEEP_UNTIL_TIMEOUT_REACHED, set when the condition was not met but timeout reached Update 2017-04-25: Thanks to @jguinchfor letting me know about Execute(). Greatly simplified the loop (didn't know that Execute would execute a function call statement) Any strings passed to the SleepUntil() function need to be enclosed in " or ' (I.e', SleepUntil("ConsoleWrite('This is a test' & @LF)")) Adjusted SleepUntil() to use the Execute() function instead Inspired by a very vague topic, and completely unnecessary, I had fun trying to making this up. A function that will sleep until the conditional statement, or function call statement, provided executes to the condition you want! I know, completely useless!!! It's pretty interesting actually. Instead of having to write multiple while loops per conditions, you just need to use SleepUntil and set your own condition. Basic syntax: SleepUntil("$iMyNumber = 100") Will sleep until the variable in your script $iMyNumber is 100. All conditional operators are supported (=, <>, >=, <=, >, and <). Currently does not support multiple conditions (i.e., $iMyNumber > 100 and $iMyNumber < 1000). More advanced syntax, using a value returned from a function call: SleepUntil("TimerDiff(" & TimerInit() & ") > 5000") Well check the value returned from TimerDiff using the value returned from TimerInit() and stop sleeping once it's > 5000 (5 seconds). Anyways, better to show through the example. Example.au3 #include <String.au3> #include <Array.au3> #include <GUIConstants.au3> #include <GuiEdit.au3> #include "SleepUntil.au3" AutoItSetOption("GUICloseOnESC", 0) Global $sName = "Test" Global $bBool = True Global $iInt = -1 Global $dDouble = 0.0 Global $sMsg = "Welcome," & @CRLF & _ "The SleepUntil function can use a function to check against a condition or just a regular conditional statement. " & _ "I.e. $iValue = 300" & @CRLF & "A basic conditional example would be" & @CRLF & @TAB & _ "Global $bWaiting = True" & @CRLF & @TAB & _ 'SleepUntil("$bWaiting <> $bWaiting")' & @CRLF & _ "This is a good example of having some kind of global flag where you want to wait until the user triggers the flag to not be true" & @CRLF & @CRLF & _ "The first set of examples will use function calls to compare against the condition value." & @CRLF & _ "First example calls GUIGetMsg using the with no arguments and sleeps until the value returned is " & _ "$GUI_EVENT_CLOSE" & @CRLF & @CRLF & _ "Syntax for the function call for SleepUntil is like normal:" & @CRLF & _ 'SleepUntil("FunctionName(Argument1, Argument2, ArgumnetN) (Condition Operator) Value' & @CRLF & _ 'Example (Where function call has arguments)' & @CRLF & @TAB & _ 'Global $iTimer = TimerInit()' & @CRLF & @TAB & _ 'SleepUntil("TimerDiff(" & $iTimer & ") >= 5000")' & @CRLF & @CRLF & _ "Example (Where no arguments are needed for the function)" & @CRLF & @TAB & _ 'SleepUntil("GUIGetMsg() = $GUI_EVENT_CLOSE")' & @CRLF & @CRLF & _ "The first example will start once you close this window!" Global $hMain = GUICreate("Introduction", 800, 600, 0, 0, BitOR($WS_SIZEBOX, $WS_MAXIMIZEBOX, $WS_MINIMIZEBOX)) Global $edtEdit = GUICtrlCreateEdit($sMsg, 10, 10, 775, 555, $ES_MULTILINE) GUICtrlSetBkColor($edtEdit, 0x1F1F1F) GUICtrlSetColor($edtEdit, 0xF1F1F1) GUICtrlSetFont($edtEdit, 11, 400, "", "Consolas") GUICtrlSetResizing($edtEdit, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM) GUISetState(@SW_SHOWMAXIMIZED) _GUICtrlEdit_SetSel(GUICtrlGetHandle($edtEdit), 0, 0) ; Slep until person running this example script closes the GUI or it reaches the 30 second timeout SleepUntil("GUIGetMsg() = $GUI_EVENT_CLOSE", 50, 30000) GUIDelete($hMain) MsgBox("", "Timer", "Starting the examples. The next sleep will last until 2 seconds have passed") ; Sleep until TimerDif(Timer Created) > 2000 ToolTip("Sleeping until 2 seconds has passed", 0, 0) SleepUntil("TimerDiff(" & TimerInit() & ") >= 2000") MsgBox("", "Timer", "2 Seconds has passed. Met condition and left sleep function") ; Sleep until the call to ConsoleWrite3Times is >= 3 ToolTip("Sleeping until the function ConsoleWrite3Times() as been called three times", 0, 0) SleepUntil("ConsoleWrite3Times('This is a test!') >= 3", 500) MsgBox("", "Print 3 Times", "Did ConsoleWrite 3 times. Met condition needed and left sleep function") MsgBox("", "Next", "Next SleepUntil examples can be met by pressing the {F1} Key to trigger the conditions" & @CRLF & _ "Next example will sleep until $sName = InunoTaishou") HotKeySet("{F1}", SetName) ; Sleep until user presses {F1} and changes $sName = InunoTaishou ToolTip("$sName = " & $sName, 0, 0) SleepUntil("$sName = 'InunoTaishou'", 100) MsgBox("", $sName, "Name has been updated to " & $sName & ". Met condition needed and left sleep function" & @CRLF & _ "Next example will sleep until $bBool <> True") ; Sleep until user preses {F1} and $bBool <> True ToolTip("$bBool = " & $bBool, 0, 0) SleepUntil("$bBool <> " & $bBool, 100) MsgBox("", $bBool, "Bool has been updated to " & $bBool & ". Met condition needed and left sleep function" & @CRLF & _ "Next example will sleep until $iInt > 0") ; Sleep until user presses {F1} and $iInt > 0 ToolTip("$iInt = " & $iInt, 0, 0) SleepUntil("$iInt > 0", 100) MsgBox("", $iInt, "Int has been updated to " & $iInt & ". Met condition needed and left sleep function" & @CRLF & _ "Next example will sleep until $dDouble = 99.99") ; Sleep until user presses {F1} and $dDouble = 99.99 ToolTip("$dDouble = " & $dDouble, 0, 0) SleepUntil("$dDouble = 99.99", 100) MsgBox("", $dDouble, "Double has been updated to " & $dDouble & ". Met condition needed and left sleep function" & @CRLF & _ "Next example will sleep until function Print is called with the msg provided") Local $sMsgToPrint = InputBox("Message", "What message should be used for ConsoleWrite?", "This is a the default msg!") SleepUntil("Print('" & $sMsgToPrint & "', " & InputBox("Times?", "How many times to print " & $sMsgToPrint & "?", 10) & ") = '" & $sMsgToPrint & "'") MsgBox("", "Print", "Congrats! That's all the examples I have") Func ConsoleWrite3Times($sMsg) Local Static $iPrint = 0 $iPrint += 1 ConsoleWrite("[" & $iPrint & "] " & $sMsg & @LF) Return $iPrint EndFunc Func Print($sMsg, $iTimes) If ($iTimes < 1) Then $iTimes = 1 For $i = 1 to $iTimes ConsoleWrite($sMsg & @LF) Next Return $sMsg EndFunc Func SetName() $sName = "InunoTaishou" HotKeySet("{F1}", SetBool) EndFunc ;==>SetName Func SetBool() $bBool = False HotKeySet("{F1}", SetInt) EndFunc ;==>SetBool Func SetInt() $iInt = 100 HotKeySet("{F1}", SetDouble) EndFunc ;==>SetInt Func SetDouble() $dDouble = 99.99 EndFunc ;==>SetDouble SleepUnti.au3 #include-once #include <String.au3> Global Const $SLEEP_UNTIL_INVALID_EXECUTE = -100 Global Const $SLEEP_UNTIL_TIMEOUT_REACHED = -101 ; #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 ; #CURRENT# ===================================================================================================================== ; SleepUntil: Sleeps until the condition statement supplied meets the requirements ; =============================================================================================================================== ; #FUNCTION# ==================================================================================================================== ; Name ..........: SleepUntil ; Description ...: Sleeps until the condition supplied is met. ; Syntax ........: SleepUntil($sConditionStatement[, $iTime = 100[, $iTimeout = Default]]) ; Parameters ....: $sConditionStatement - String formatted condition statement ; $iTime - (Optional) Time (In Milliseconds) to sleep between each check of the condition ; $iTimeout - (Optional) Timeout (In Milliseconds) to stop sleeping if condition not met ; Return values .: Success - Returns True when the condition is met ; Failure - Returns False and Sets the @Error flag ; -100 ($SLEEP_UNTIL_INVALID_EXECUTE): Function supplied does not exist or parameters supplied do not match ; the function called ; -101 ($SLEEP_UNTIL_TIMEOUT_REACHED): Timeout was reached but the condition was not met ; Author ........: InunoTaishou, jguinch for letting me know about Execute() ; Thanks jguinch! Greatly simplified the script ; Remarks .......: The $sConditionStatement parameter can be a simple $vVar = Value or can use the value returned from a function call ; to sleep. ; Proper syntax for a function call is a normal AutoIt function call: "MsgBox(0, 'Title', 'Message')" ; Example .......: Yes ; =============================================================================================================================== Func SleepUntil($sConditionStatement, $iTime = 100, $iTimeout = Default) Local $iTimer = ($iTimeout ? TimerInit() : Null) While (Not Execute($sConditionStatement)) If (@Error) Then Return SetError($SLEEP_UNTIL_INVALID_EXECUTE, 0, False) If ($iTimeout and TimerDiff($iTimer) >= $iTimeout) Then Return SetError($SLEEP_UNTIL_TIMEOUT_REACHED, 0, False) Sleep($iTime) WEnd Return True EndFunc ;==>SleepUntil Edit: Did a test call to the function to make sure it's valid. checking for the 0xDEAD and 0xBEEF errors inside the while loops wasn't working since the _EvalCondition was being called right after it. Edit: Forgot about the _ that can be used in function calls. Added the _ to the StringRegExp
-
I have automated an install process by using the below code. Func _WinWaitActivate($title,$text,$timeout=0) WinWait($title,$text,$timeout) If Not WinActive($title,$text) Then WinActivate($title,$text) WinWaitActive($title,$text,$timeout) EndFunc $win1 = "Text 1" $win2 = "Text 2" _WinWaitActivate($win1,"WARNING: This progra") Send("{ALTDOWN}n{ALTUP}");Send("{SPACE}") _WinWaitActivate($win1,"I DISAGREE and &do n") Send("{UP}n") _WinWaitActivate($win1,"Customer Information") Send("{ALTDOWN}n{ALTUP}");Send("{TAB}{TAB}n") _WinWaitActivate($win1,"Click Next to instal") Send("{ALTDOWN}n{ALTUP}");Send("n") _WinWaitActivate($win1,"This feature require") Send("{ALTDOWN}n{ALTUP}");Send("{TAB}n") _WinWaitActivate($win1,"Ready to Install the") Send("{ALTDOWN}i{ALTUP}");Send("i") _WinWaitActivate($win1,"The InstallShield Wi") Send("{ALTDOWN}f{ALTUP}");Send("f") _WinWaitActivate($win2,"You must restart you") Send("{ALTDOWN}n{ALTUP}");Send("n") Now if any new screen comes in the middle of installation, like some VC++ installation error or like that. The AutoIT is waiting in the background. Is there any way to skip the new screens with just "enter" and continue the installation??
-
I'm going to build a new function that I have been unable to find. PLEASE CORRECT ME. It will tweak the internal AutoIt functions giving me the ability to trash stuff I do not want to spin around. Get it? Please throw me whatever you got and I will put it togeather. Ship it now. My supersleep() will be in here somewhere. It's on another thread.
-
I have a light bulb which I can turn on and off using UDP commands (I already have that working in AutoIt). What I would like to do is run a script before the computer goes to sleep to turn it off, and after it resumes to turn it on. I've already got the latter working, but not the former. I tried Task Scheduler with the kernel power log, but the command doesn't get executed until the computer resumes from sleep. I've tried some things using WM_POWERBROADCAST, but so far I haven't got that to work either. Here's what I've got so far: Global Const $WM_POWERBROADCAST = 0x218 Global Const $PBT_APMSUSPEND = 0x4 Global Const $PBT_APMRESUMEAUTOMATIC = 0x12 While 1 Sleep(100) WEnd GUICreate("Event Receiver") GUIRegisterMsg($WM_POWERBROADCAST,"MY_WM_POWERBROADCAST") Func MY_WM_POWERBROADCAST($hWnd, $uMsg, $wParam, $lParam) Switch $wParam Case $PBT_APMSUSPEND MsgBox(0,"PBT_APMSUSPEND","PBT_APMSUSPEND"&@HOUR&@MIN&@SEC) Case $PBT_APMRESUMEAUTOMATIC MsgBox(0,"PBT_APMSUSPEND","PBT_APMRESUMEAUTOMATIC"&@HOUR&@MIN&@SEC) EndSwitch EndFunc Does anyone know how to make this work?
-
When sleep is set to 500 and above it's causing the event that follows it to output 3 commands. In the following example the down keystroke is sent 3 times! Sleep(500) Send("{DOWN}",0) In the following example the down keystroke is sent once. Sleep(400) Send("{DOWN}",0) Why is it doing this? How do I stop sleep interfering with the event that follows it?
- 10 replies
-
- sleep
- 3 commands
-
(and 1 more)
Tagged with:
-
Hello. I'd like to ask a question about AutoIt basics, as I was deeply thinking about creating a script, I got stuck at some questions such as: The Sleep function stops the script completely (it stops everything, if the script repeats an action every 5 seconds and there is a Sleep(1000), will it repeat once per 6 seconds in real time)? Can there be multiple loops working simultaneously depending on IFs or Switches? (loops controlling keyboard, deducing things from imagesearch etc.) If there can be multiple loops working in one moment (multiple actions), does Sleep stop the whole script or just one of the loops? Thanks for responses.
-
Hello guys, suddenly i'm having a problem with Sleep() func. When i give it less time like Sleep(2000), works, but when i tell it to sleep longer like Sleep(1000*60*3), it won't work... in fact is a surprise because it used to work perfectly.. anyone knows how to help? SugarBall
-
I'm writing a small prog that will run in the background and sound an alarm if a certain Gmail message arrives in an otherwise unused account. My inclination is to use a simple While/WEnd loop with a 5 minute Sleep between checking for messages, but I've seen examples here of somewhat similar background tasks that employ AdlibRegister so I'm curious which method is the most reliable and least impactful on the CPU. Below are two simple scripts that begin to do what I want and represent how I think this could be handled. While/WEnd with Sleep #include <CheckMail.au3> Global $aReturn Global $iEmails While 1 $aReturn = CheckMail("username", "password") $iEmails = @extended If $iEmails > 0 ExitLoop Sleep(300000) ; check for new messages every 5 minutes WEnd ;work with contents of $aReturn array that contains the new message(s) found While/WEnd with Sleep and AdlibRegister #include <CheckMail.au3> Global $aReturn Global $iEmails = 0 AdlibRegister('_CallCheckMail',300000) ; check for new messages every 5 minutes While 1 Sleep(500000) ; I had to put something here. Does higher the value = less CPU demand? If $iEmails > 0 ExitLoop WEnd ;work with contents of $aReturn array that contains the new message(s) found Func _CallCheckMail $aReturn = CheckMail("username", "password") $iEmails = @extended Return EndFunc
-
I'm looking possible ways to optimize sleep time in a script which has multiple sleep times for save, refresh etc. The sleep duration varies from 5 secs to 17 secs time to time (depending upon the record, computer performance etc). Currently I set max sleep duration. ie sleep(17000). I'm looking possible ways to dynamically change sleep duration rather than fixed maximum duration. Note: winwait is not helpful in my script. Thanks in advance for your responses
- 3 replies
-
- Sleep
- Optimize Sleep
-
(and 1 more)
Tagged with:
-
Is there some way to sleep only progress bar functionality, not whole program? example: #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Form1", 421, 209, 243, 159) $close = GUICtrlCreateButton("Close", 153, 112, 119, 33) $Button1 = GUICtrlCreateButton("Run", 23, 112, 119, 33) $Progress1 = GUICtrlCreateProgress(88, 40, 257, 33) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE, $close Exit Case $Button1 For $i = 0 To 100 GUICtrlSetData($progress1, $i) Sleep(5) Next sleep(5000) GUICtrlSetData($progress1, 0) EndSwitch WEnd here I can not close the form, because sleep(5000) is still running
-
Hello, I noticed on several installations that the Sleep statment causes CPU issues when the customer hardware is a powerfull one. For example: While 1 Sleep(5000) Wend Shall cost 0% CPU But is the hardware is fast the Sleep(5000) costs 3 % CPU when included into a loop. So, if 50 users start this script concurrent it overkill the CPU (which is not good of course). In such cases, the workaround I am using is to set a much longuer delay fo such specific case, but this is not a good solution because the script behavior is unpredictable. Can you help me on that specific problem? Kind regards Dominique Benoit
-
How can I stop any function that is running and restart main function? My program keeps stacking points to go back, isn't it? How can I fix it? HotKeySet("{F8}", "StartStop") HotKeySet("{ESC}", "Quit") Global $status = -1, $cont Tray() Main() Func Main() $cont = 0 While 1 If $status = 1 Then Cont100() Switch TrayGetMsg() Case $ExitTray Exit Case $OptionsTray MsgBox(0, "Options", "Options") EndSwitch WEnd EndFunc Func Cont100() While $cont < 100 SplashTextOn("", $cont+1, 100, 50, 0, 0) $cont += 1 Sleep(1000) WEnd EndFunc Func Tray() Opt("TrayMenuMode",1) Global $OptionsTray = TrayCreateItem("Options") Global $ExitTray = TrayCreateItem("Exit") TraySetToolTip("NeoBux Bot - By FiMo") EndFunc Func StartStop() $status *= -1 Main() EndFunc Func Quit() Exit EndFunc
-
I have a script that monitors network up/down time and when my laptop is set to hibernate or sleep, then later started up again, my script counts all of the hibernate/sleep time as down time. If I could get notification when going into hibernate/sleep mode and when it resumes normal mode, I could stop looking until normal mode is resumed. Is there an API that does this, or perhaps an event I could register a handler for? Andy
-
Hello, I have this simple script which automates google translate. #include <IE.au3> $oIE = _IECreate("http://translate.google.com/#en|fr|") $oForm = _IEFormGetObjByName($oIE, "text_form") $oText = _IEFormElementGetObjByName($oForm, "text") _IEFormElementSetValue($oText, "Hello") Sleep(3000) $id = _IEGetObjById($oIE, "result_box") $oText1 = _IEPropertyGet($id, "innertext") MsgBox(0,"Translate",$oText1) What i want to do it to remove the Sleep(3000) that there is in the script. But removing it the script doesnt works because the message box appears before geting the value of the innertext.... Is there a way to remove or replace the sleep time??? I tried _IELoadWait() but it doesnt work. Any tips?? Edit: Testing for the $oText1.value just add some more pointless lines to the script and leeds at adding sleep seconds until value is true...
-
Hi all, My first uploaded UDF So this is just an improvised version of the Sleep function. It allows the script to sleep, as normal, while still running code. This would be useful if you want your script to sleep for a long period of time, but for your GUI to still be fully functional. So, if you have your script sleep for 5 minutes, and want your GUI to close when you click on the close button, then this will allow you to do it. I've included the basic switch for the GuiGetMsg() function with the $GUI_EVENT_CLOSE in it, but left everything else out, so that you can customize and edit it to fit your needs. It takes two parameters: The first one is how long it should wait, in milliseconds, just like the regular sleep function. The second parameter is optional (has a default at 10), and is for how long it should pause while running through its while loop. Here it is: Func Sleep2($waitTime, $pauseTime = 10) Local $finishTime = $waitTime + (@YDAY * 86400000) + (@HOUR * 3600000) + (@MIN * 60000) + (@SEC * 1000) + @MSEC While 1 Local $currentTime = (@YDAY * 86400000) + (@HOUR * 3600000) + (@MIN * 60000) + (@SEC * 1000) + @MSEC If $currentTime >= $finishTime Then ExitLoop $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch Sleep($pauseTime) WEnd EndFunc If you want to test it, run this code- it shows a tooltip displaying the current milisecond we are at in the year, then pauses for 5 seconds, and displays the new current time right below it. $time = (@YDAY * 86400000) + (@HOUR * 3600000) + (@MIN * 60000) + (@SEC * 1000) + @MSEC ToolTip($time) Sleep2(5000) ToolTip($time & @CRLF & ((@YDAY * 86400000) + (@HOUR * 3600000) + (@MIN * 60000) + (@SEC * 1000) + @MSEC)) While 1 Sleep(30) WEnd Tell me what you think. If you want to download it as a file, here it is: