Kalin Posted January 12, 2011 Share Posted January 12, 2011 (edited) I don't know if anyone has thought of this, but I came up with the idea during school. This script allows you to input seconds instead of milliseconds in the Sleep(). I might update this in the near future considering I have a couple of ideas for it. Here's the short snippet: Func SleepX($iTime) $arithmetic = $iTime * 1000 Sleep($arithmetic) EndFunc Example: ConsoleWrite("HUR DUR" & @LF) SleepX(3) ; Idles for three seconds then calls the next function ConsoleWrite("DERP HERP") Edited January 12, 2011 by Kalin Link to comment Share on other sites More sharing options...
AU3Newbie Posted January 12, 2011 Share Posted January 12, 2011 I don't know if anyone has thought of this, but I came up with the idea during school. This script allows you to input seconds instead of milliseconds in the Sleep(). I might update this in the near future considering I have a couple of ideas for it. Here's the short snippet: Func SleepX($iTime) $arithmetic = $iTime * 1000 Sleep($arithmetic) EndFunc Example: ConsoleWrite("HUR DUR" & @LF) SleepX(3) ; Idles for three seconds then calls the next function ConsoleWrite("DERP HERP") I've seen someone did it better before. Link to comment Share on other sites More sharing options...
BinaryBrother Posted January 12, 2011 Share Posted January 12, 2011 I've seen someone did it better before.I didn't find that constructive at all. The most important thing you're missing is an example. Negating the fact that making this "better" goes beyond the scope of the initial function's purpose. Which looks pretty rock-solid to me... o.0Which brings me down to my initial and current response to your statement...How so? Please do share. SIGNATURE_0X800007D NOT FOUND Link to comment Share on other sites More sharing options...
Kalin Posted January 12, 2011 Author Share Posted January 12, 2011 I've seen someone did it better before.*do Doesn't get much better than this.Proof or gtfo.Also, lol @ your username. Link to comment Share on other sites More sharing options...
BinaryBrother Posted January 12, 2011 Share Posted January 12, 2011 It's almost as if the Developer God's are trying to prove a point... o.0 SIGNATURE_0X800007D NOT FOUND Link to comment Share on other sites More sharing options...
CarlMontgomery Posted January 12, 2011 Share Posted January 12, 2011 (edited) I think Kalin's example is brilliant. It's clear, concise coding the way i like it.It's inspired me to expand on it. Below is my SleepXX UDF which alows to so sleep the script for various units of time.It's quick and dirty and really requires more development. Currently it doesnt support enough units of measure.Credit to Kalin for the idea Usage:SleepXX ( $iTime[,"$sUnit"] )Parameters:$iTime - Integer number you want to sleep.$sUnit - String unit of time measurement.Example:#include "SleepXX.au3" ConsoleWrite("HUR DUR" & @LF) SleepXX(3 , "second") ; Idles for three seconds then calls the next function ConsoleWrite("DERP HERP"& @LF) SleepXX(2 , "microfortnight") ; Idles for two micro-fortnights then calls the next function ConsoleWrite("OMGWTFBBQ")Current supported units of time measurement:microsecond - 1/100 of a secondsecond - one second (this is the default)minute - 60 secondshour - 60 minutesday - 24 hoursweek - 7 daysfortnight - 2 weeksyear - 365 daysswatch - swatch beat - 1 minute and 26.4 seconds (http://en.wikipedia.org/wiki/Swatch_Internet_Time)lunarday - Average Lunar day - 29 days, 12 hours, 44 minutes and 3 seconds (http://en.wikipedia.org/wiki/Lunar_day)gaussianyear - 365.2568983 days (http://en.wikipedia.org/wiki/Gaussian_year)galacticyear - Galactic year - 225 million years - http://en.wikipedia.org/wiki/Galactic_yearhelek - hewbrew helek - 3 and one thrird seconds (http://en.wikipedia.org/wiki/Helek)samay - hindu samay - quarter of a second (http://en.wikipedia.org/wiki/Samay)Atom - from philosophical writing. 15/94 of a second (http://en.wikipedia.org/wiki/Atom_%28time%29)jiffy - Linux Jiffy - 4 ms (http://en.wikipedia.org/wiki/Jiffy_%28time%29)microfortnight - 1.2096 seconds (http://en.wikipedia.org/wiki/List_of_unusual_units_of_measurement#Time)blinkofaneye - A Blink Of An Eye - 25 millisecondstwoshakesofalambstail - Two shakes of a lambs tail - two fifths of a second. My mother told me so and she knows everything.integermax - Maximum possible sleep time as per 64 bit signed integer limit. 292 277 266 years. Specifying more than one will produce an overflow errorEdit: V0.2 added the following:medievalostent - medieval ostent - 1/10 hour ( http://www.encyclo.co.uk/define/Ostent )medievalmoment - medieval moment - 1/40 of an hour ( http://en.wikipedia.org/wiki/Moment_%28time%29 )inyourowntime- in your own time - random sleep anywhere between 1 second and an hour (and multiples there of)fiveninesdowntime - five nines down time - Downtime per year when uptime is the "five nines" (99.999%) - 5 minutes and 15.36 secondsHummingbirdWingbeat - Wingbeat of a small Humming bird - somewhere between 12 and 26 milliseconds. Can be used to approximate the velocity of an unladened swallow ( http://hypertextbook.com/facts/2000/MarkLevin.shtml )expandcollapse popup#Region Description ;=============================================================================== ; Description: Expands on the default sleep function by sleeping specific units of time ; Based on and inspired by Kalin ( http://www.autoitscript.com/forum/topic/124141-sleepx/ ) ; ; Parameter(s): $iTime - specified time (number Of intervals) ; $sUnit - String unit of measure that can be any of the below: ; ; microsecond - 1/100 of a second ; second - one second (this is the default) ; minute - 60 seconds ; hour - 60 minutes ; day - 24 hours ; week - 7 days ; fortnight - 2 weeks ; year - 365 days ; swatch - swatch beat - 1 minute and 26.4 seconds (http://en.wikipedia.org/wiki/Swatch_Internet_Time) ; lunarday - Average Lunar day - 29 days, 12 hours, 44 minutes and 3 seconds (http://en.wikipedia.org/wiki/Lunar_day) ; gaussianyear - 365.2568983 days (http://en.wikipedia.org/wiki/Gaussian_year) ; galacticyear - Galactic year - 225 million years - http://en.wikipedia.org/wiki/Galactic_year ; helek - hewbrew helek - 3 and one thrird seconds (http://en.wikipedia.org/wiki/Helek) ; samay - hindu samay - quarter of a second (http://en.wikipedia.org/wiki/Samay) ; Atom - from philosophical writing. 15/94 of a second (http://en.wikipedia.org/wiki/Atom_%28time%29) ; jiffy - Linux Jiffy - 4 ms (http://en.wikipedia.org/wiki/Jiffy_%28time%29) ; microfortnight - 1.2096 seconds (http://en.wikipedia.org/wiki/List_of_unusual_units_of_measurement#Time) ; blinkofaneye - A Blink Of An Eye - 25 milliseconds ; twoshakesofalambstail - Two shakes of a lambs tail - two fiths of a second. My mother told me so and she knows everything. ; integermax - Maximum possible sleep time as per 64 bit signed interger limit. 292 277 266 years. Specifying more than one will produce an overflow error ;added in version 0.2 ; medievalostent - medieval ostent - 1/10 hour ( http://www.encyclo.co.uk/define/Ostent ) ; medievalmoment - medieval moment - 1/40 of an hour ( http://en.wikipedia.org/wiki/Moment_%28time%29 ) ; inyourowntime- in your own time - random sleep anywhere between 1 second and an hour (and multiples there of) ; fiveninesdowntime - five nines down time - Downtime per year when uptime is the "five nines" (99.999%) - 5 minutes and 15.36 seconds ; HummingbirdWingbeat - Wingbeat of a small Humming bird - somewhere between 12 and 26 milliseconds. Can be used to approximate the velocity of an unladened swallow ( http://hypertextbook.com/facts/2000/MarkLevin.shtml ) ; ; Requirement(s): None ; ; Author(s): Kalin & Carl Montgomery ; ; Note(s): if unit is not specified or incorrectly spelled then seconds is used as default ; ; Version History 0.1 - 13 jan 2011 - initial version ; 0.2 - 14 jan 2011 - added extra units of time and fixed the odd embarresing tyro ;=============================================================================== #EndRegion Description Func SleepXX($iTime, $sUnit) Select Case $sUnit = "microsecond" $iMultiplyer = 10 Case $sUnit = "second" $iMultiplyer = 1000 Case $sUnit = "minute" $iMultiplyer = 60000 Case $sUnit = "hour" $iMultiplyer = 3600000 Case $sUnit = "day" $iMultiplyer = 86400000 Case $sUnit = "day" $iMultiplyer = 86400000 Case $sUnit = "week" $iMultiplyer = 604800000 Case $sUnit = "fortnight" $iMultiplyer = 1209600000 Case $sUnit = "year" $iMultiplyer = 31536000000 Case $sUnit = "swatch" $iMultiplyer = 86400 Case $sUnit = "lunarday" $iMultiplyer = 2551443000 Case $sUnit = "gaussianyear" $iMultiplyer = 31558196000 Case $sUnit = "galacticyear" $iMultiplyer = 7095600000000000000 Case $sUnit = "helek" $iMultiplyer = 3333.3333333333333 Case $sUnit = "samay" $iMultiplyer = 250 Case $sUnit = "Atom" $iMultiplyer = 159.57446808510638297872340425532 Case $sUnit = "jiffy" $iMultiplyer = 4 Case $sUnit = "microfortnight" $iMultiplyer = 1209.6 Case $sUnit = "blinkofaneye" $iMultiplyer = 25 Case $sUnit = "twoshakesofalambstail" $iMultiplyer = 400 Case $sUnit = "integermax" $iMultiplyer = 9223372036854775807 ;added in version 0.2 Case $sUnit = "medievalostent" $iMultiplyer = 360000 Case $sUnit = "medievalmoment" $iMultiplyer = 90000 Case $sUnit = "inyourowntime" $iMultiplyer = Random(1000, 3600000) Case $sUnit = "fiveninesdowntime" $iMultiplyer = 315360 Case $sUnit = "HummingbirdWingbeat" $iMultiplyer = Random(12, 26) Case Else $iMultiplyer = 1000 EndSelect $arithmetic = $iTime * $iMultiplyer Sleep($arithmetic) EndFunc ;==>SleepXXEdit: v0.3 now attachedSleepXX.au3 Edited January 13, 2011 by CarlMontgomery Link to comment Share on other sites More sharing options...
JohnOne Posted January 12, 2011 Share Posted January 12, 2011 (edited) Your UDF is missing "two shakes of a lambs tail"No it isnt soft lad. Its perfect, thanks Edited January 12, 2011 by JohnOne 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...
CarlMontgomery Posted January 12, 2011 Share Posted January 12, 2011 Your UDF is missing "two shakes of a lambs tail"No it isnt soft lad. Its perfect, thanksthanks. Just need to include "At the drop of a hat"Still trying to work out exactly how long until "Hell freezes over"Perhaps in the next version. Link to comment Share on other sites More sharing options...
Ascend4nt Posted January 12, 2011 Share Posted January 12, 2011 Brilliant. Someone can do math, I'm amazed. On the serious side, if you'd like a real UDF that actually does something useful, check out 'Oh and by the way, CarlMontgomery - microsecond is 1/1000 of a millisecond, or 1 millionth of a second. You can't go that low with normal Sleep, which takes milliseconds. My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs |Â Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) |Â Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code) Link to comment Share on other sites More sharing options...
CarlMontgomery Posted January 12, 2011 Share Posted January 12, 2011 (edited) Brilliant. Someone can do math, I'm amazed. On the serious side, if you'd like a real UDF that actually does something useful, thanks for that. that is a useful UDF. Have filed it away for future use.Are you implying my UDF isn't useful? I've even updated the UDF with these extra units of time measurement.medievalostent - medieval ostent - 1/10 hour ( http://www.encyclo.co.uk/define/Ostent )medievalmoment - medieval moment - 1/40 of an hour ( http://en.wikipedia.org/wiki/Moment_%28time%29 )inyourowntime- in your own time - random sleep anywhere between 1 second and an hour (and multiples there of)fiveninesdowntime - five nines down time - Downtime per year when uptime is the "five nines" (99.999%) - 5 minutes and 15.36 secondsHummingbirdWingbeat - Wingbeat of a small Humming bird - somewhere between 12 and 26 milliseconds. Can be used to approximate the velocity of an unladened swallow ( http://hypertextbook.com/facts/2000/MarkLevin.shtml )Edit: v0.3 now attachedSleepXX.au3 Edited January 13, 2011 by CarlMontgomery Link to comment Share on other sites More sharing options...
Kalin Posted January 12, 2011 Author Share Posted January 12, 2011 (edited) What you implemented in my script was one of the ideas I had in mind. But unfortunately you beat me to it. Thanks for extending it, you saved me some time.And yes, he was implying that your UDF is useless.Anyways @ topic, I've noticed that your extensions to the script are always ascending, why not give your UDF the capabilities of the UDF that Ascend4nt mentioned? It'd be nice to be able to go lower than milliseconds. But yeah, nice to see that my short snippet evolved into something big. Edited January 12, 2011 by Kalin Link to comment Share on other sites More sharing options...
JohnOne Posted January 12, 2011 Share Posted January 12, 2011 #include <Misc.au3> Func _Snooze($delay) Sleep($delay) Do Beep(700,300) Sleep(1000) Until _IsPressed("01") EndFunc Needs a bit of work, if I have time this summer, I'll update it. 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...
Newb Posted January 13, 2011 Share Posted January 13, 2011 Sorry but i find this useless. All of these can be obtained by dividing/multiplying the sleep time value with no effort at all... Don't see why we would need an udf to make a division/multiplication. Sleep(3*1000) pauses for 3 seconds Sleep(3*1000*60) pauses for 3 minutes and so on. Who would need to pause for "blink of an eye" or "fortnight" or for "gaussianyear"??? You can just have 2 minutes of fan with this udf. No use at all. I know it's a joke, but put effort in making something useful next time. I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it. Link to comment Share on other sites More sharing options...
JohnOne Posted January 13, 2011 Share Posted January 13, 2011 Thanks for that captain buzzkill. 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...
CarlMontgomery Posted January 13, 2011 Share Posted January 13, 2011 (edited) Needs a bit of work, if I have time this summer, I'll update it. Made some necessary improvements. #include <Misc.au3> #include "SleepXX.au3" Func _Snooze($delay) SleepXX($delay * 0.25 , "Jiffy") Do Beep(700,300) SleepXX(2,"twoshakesofalambstail") SleepXX(8,"blinkofaneye") Until _IsPressed("01") EndFunc Edited January 13, 2011 by CarlMontgomery Link to comment Share on other sites More sharing options...
Malkey Posted January 13, 2011 Share Posted January 13, 2011 @Kalin Your SleepX() UDF did not work in this example.So this is a complete rewrite of your SleepX() function to make it work on my xp.Do Until SleepX(5) MsgBox(0, "Sleep(20)", "Sleep returns: " & Sleep(20), 3) Sleep(2147483648) ; Over the limit MsgBox(0, "Sleep(2147483648)", "Sleep with 1 millisecond over its limit of " & _ Int(24 * 24 * 60 * 60 * 1000 * 1.0356306168017) & " milliseconds (24 days approx.)") ;Sleep(2147483647) ; Sleep's limit Func SleepX($iTime) Return Sleep($iTime * 1000) EndFunc ;==>SleepX@CarlMontgomery From Sleep function in the help file.Return Value None. Remarks Maximum sleep time is 2147483647 milliseconds (24 days).Your UDF will need correcting just in case captain buzzkill decides to secretly check SleepXX( 1, "gaussianyear").@no one in particular.One is almost none on so many levels. Link to comment Share on other sites More sharing options...
CarlMontgomery Posted January 13, 2011 Share Posted January 13, 2011 (edited) @CarlMontgomery .... Maximum sleep time is 2147483647 milliseconds (24 days). Your UDF will need correcting just in case captain buzzkill decides to secretly check SleepXX( 1, "gaussianyear"). @no one in particular. One is almost none on so many levels. Thanks for the beta testing. Totally missed that bug. Didnt have a spare gaussian year to do testing Anyway, A fixed version is now attached. Captain buzz kill can now rest easy knowing next time (s)he needs to sleep a script for a galactic year, (s)he can do so in style Carl expandcollapse popup#Region Description ;=============================================================================== ; Description: Expands on the default sleep function by sleeping specific units of time ; Based on and inspired by Kalin ( http://www.autoitscript.com/forum/topic/124141-sleepx/ ) ; ; Parameter(s): $iTime - specified time (number Of intervals) ; $sUnit - String unit of measure that can be any of the below: ; ; microsecond - 1/100 of a second ; second - one second (this is the default) ; minute - 60 seconds ; hour - 60 minutes ; day - 24 hours ; week - 7 days ; fortnight - 2 weeks ; year - 365 days ; swatch - swatch beat - 1 minute and 26.4 seconds (http://en.wikipedia.org/wiki/Swatch_Internet_Time) ; lunarday - Average Lunar day - 29 days, 12 hours, 44 minutes and 3 seconds (http://en.wikipedia.org/wiki/Lunar_day) ; gaussianyear - 365.2568983 days (http://en.wikipedia.org/wiki/Gaussian_year) ; galacticyear - Galactic year - 225 million years - http://en.wikipedia.org/wiki/Galactic_year ; helek - hewbrew helek - 3 and one thrird seconds (http://en.wikipedia.org/wiki/Helek) ; samay - hindu samay - quarter of a second (http://en.wikipedia.org/wiki/Samay) ; Atom - from philosophical writing. 15/94 of a second (http://en.wikipedia.org/wiki/Atom_%28time%29) ; jiffy - Linux Jiffy - 4 ms (http://en.wikipedia.org/wiki/Jiffy_%28time%29) ; microfortnight - 1.2096 seconds (http://en.wikipedia.org/wiki/List_of_unusual_units_of_measurement#Time) ; blinkofaneye - A Blink Of An Eye - 25 milliseconds ; twoshakesofalambstail - Two shakes of a lambs tail - two fiths of a second. My mother told me so and she knows everything. ; integermax - Maximum possible sleep time as per 64 bit signed interger limit. 292 277 266 years. Specifying more than one will produce an overflow error ;added in version 0.2 ; medievalostent - medieval ostent - 1/10 hour ( http://www.encyclo.co.uk/define/Ostent ) ; medievalmoment - medieval moment - 1/40 of an hour ( http://en.wikipedia.org/wiki/Moment_%28time%29 ) ; inyourowntime- in your own time - random sleep anywhere between 1 second and an hour (and multiples there of) ; fiveninesdowntime - five nines down time - Downtime per year when uptime is the "five nines" (99.999%) - 5 minutes and 15.36 seconds ; HummingbirdWingbeat - Wingbeat of a small Humming bird - somewhere between 12 and 26 milliseconds. Can be used to approximate the velocity of an unladened swallow ( http://hypertextbook.com/facts/2000/MarkLevin.shtml ) ; ; Requirement(s): None ; ; Author(s): Kalin & Carl Montgomery ; ; Note(s): if unit is not specified or incorrectly spelled then seconds is used as default ; ; Version History 0.1 - 12 jan 2011 - initial version ; 0.2 - 13 jan 2011 - added extra units of time and fixed the odd embarresing tyro ; 0.3 - 13 jan 2011 - fixed a bug where sleeps over 24 days did not work. thanks to Malkey for pointing this out. ;=============================================================================== #EndRegion Description Func SleepXX($iTime, $sUnit) Select Case $sUnit = "microsecond" $iMultiplyer = 10 Case $sUnit = "second" $iMultiplyer = 1000 Case $sUnit = "minute" $iMultiplyer = 60000 Case $sUnit = "hour" $iMultiplyer = 3600000 Case $sUnit = "day" $iMultiplyer = 86400000 Case $sUnit = "day" $iMultiplyer = 86400000 Case $sUnit = "week" $iMultiplyer = 604800000 Case $sUnit = "fortnight" $iMultiplyer = 1209600000 Case $sUnit = "year" $iMultiplyer = 31536000000 Case $sUnit = "swatch" $iMultiplyer = 86400 Case $sUnit = "lunarday" $iMultiplyer = 2551443000 Case $sUnit = "gaussianyear" $iMultiplyer = 31558196000 Case $sUnit = "galacticyear" $iMultiplyer = 7095600000000000000 Case $sUnit = "helek" $iMultiplyer = 3333.3333333333333 Case $sUnit = "samay" $iMultiplyer = 250 Case $sUnit = "Atom" $iMultiplyer = 159.57446808510638297872340425532 Case $sUnit = "jiffy" $iMultiplyer = 4 Case $sUnit = "microfortnight" $iMultiplyer = 1209.6 Case $sUnit = "blinkofaneye" $iMultiplyer = 25 Case $sUnit = "twoshakesofalambstail" $iMultiplyer = 400 Case $sUnit = "integermax" $iMultiplyer = 9223372036854775807 ;added in version 0.2 Case $sUnit = "medievalostent" $iMultiplyer = 360000 Case $sUnit = "medievalmoment" $iMultiplyer = 90000 Case $sUnit = "inyourowntime" $iMultiplyer = Random(1000, 3600000) Case $sUnit = "fiveninesdowntime" $iMultiplyer = 315360 Case $sUnit = "HummingbirdWingbeat" $iMultiplyer = Random(12, 26) Case Else $iMultiplyer = 1000 EndSelect $arithmetic = $iTime * $iMultiplyer ;check to see if the sleep goes over Autoit's 24 day limit If $arithmetic > 2147483647 Then ;calulate a sleep loop $iSleepLoop = Floor($arithmetic / 2147483647) ;calculate the ramainder $iSleepRemainder = $arithmetic - ($iSleepLoop * 2147483647) ;start the 24 day sleep loop For $loop = 1 To $iSleepLoop Sleep(2147483647) Next ;now sleep for the remainder Sleep($iSleepRemainder) Else ; just run the sleep as is Sleep($arithmetic) EndIf EndFunc ;==>SleepXXSleepXX.au3 Edited January 13, 2011 by CarlMontgomery 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