AutoHotkey Community

It is currently May 27th, 2012, 11:59 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: November 13th, 2010, 4:22 pm 
Offline
User avatar

Joined: April 4th, 2009, 8:19 pm
Posts: 1143
Location: Croatia
Sleep in seconds, minutes, hours or days. Very short and simple. No more calculations like how many miliseconds are in 2 hours?
Related: Sleep Until Time by None
Code:
Sleep(n,u) { ; Sleep in seconds, minutes, hours or days. By Learning one, SKAN and MasterFocus.
   Sleep, % ( n*1000* (((u:=SubStr(u,1,1))="s") ? 1 : (u="m") ? 60 : (u="h") ? 3600 : (u="d") ? 86400 : 0 ))
}

/*
; Examples:
Sleep(3, "seconds")    ; (seconds,second,sec,s --> all the same)
Sleep(1, "min")         ; (minutes,minute,min,m --> all the same)
Sleep(1, "h")         ; (hours,hour,h --> all the same)
Sleep(0.5, "day")      ; (days,day,d --> all the same)
*/

Original version:
Code:
Sleep(number,unit) {   ; Sleep in seconds, minutes, hours or days. By Learning one.
   Static u := "s1000|m60000|h3600000|d86400000"
   Loop, parse, u, |
   {
      if (SubStr(A_LoopField,1,1) = SubStr(unit,1,1))
      Sleep, % number*SubStr(A_LoopField,2)
   }
}


Last edited by Learning one on November 19th, 2010, 7:02 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 18th, 2010, 2:15 pm 
Offline

Joined: January 7th, 2007, 1:43 pm
Posts: 107
good.thank you.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 18th, 2010, 4:14 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Ternary based...

Code:
Sleep( n,u ) {
 Sleep, % SubStr( u := SubStr( u,1,1 ), 1, 0 ) . ( n * ( (u="s") ? 1000 : (u="m") ? 60000
        : (u="h") ? 3600000 : (u="d") ? 86400000 : 0 ))
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 18th, 2010, 6:27 pm 
Offline
User avatar

Joined: July 17th, 2008, 12:58 am
Posts: 270
very usefull thank you!

_________________
QuickSubs | Popcorn Movie Db
All my scripts are just in AutoHotkey v1.0.48.05


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 19th, 2010, 4:31 am 
Offline

Joined: April 8th, 2009, 8:23 pm
Posts: 3036
Location: Rio de Janeiro - RJ - Brasil
@SKAN: Wouldn't the inner SubStr be enough?
Code:
Sleep( n,u ) {
 Sleep, % ( n*1000* ( ((u:=SubStr(u,1,1))="s") ? 1 : (u="m") ? 60
        : (u="h") ? 3600 : (u="d") ? 86400 : 0 ))
}

_________________
"Read the manual. Read it again. Search the forum.
Try something before asking. Show what you've tried.
"
Image
Antonio França
My stuff: Google Profile


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 19th, 2010, 8:26 am 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
@MasterFocus: Neat!.. I love it :D


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 19th, 2010, 5:24 pm 
Offline
User avatar

Joined: May 5th, 2007, 7:24 pm
Posts: 1240
Location: Seville, Spain
Here's my take:
Code:
Sleep(n, u="s")
{
   Sleep % n * ((u := SubStr(u, 1, 1)) = "s" ? 1000
               : u = "m" ? 60000
               : u = "h" ? 3600000
               : u = "d" ? 86400000
               : 0)
}

Just because it is compact doesn't mean it has to be unreadable.

_________________
fincs
Highly recommended: AutoHotkey_L (see why) (all my code snippets require it)
Formal request to polyethene - I support the unity of the AutoHotkey community
Get SciTE4AutoHotkey v3.0.00 (Release Candidate)
[My project list]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 19th, 2010, 7:03 pm 
Offline
User avatar

Joined: April 4th, 2009, 8:19 pm
Posts: 1143
Location: Croatia
1. post updated with short version.

P.S. maybe suggestion for Sleep command in AHK_L:
Sleep, delay [, unit]


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: notsoobvious, rrhuffy and 16 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group