AutoHotkey Community

It is currently May 27th, 2012, 6:56 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: May 25th, 2008, 1:49 pm 
Offline

Joined: April 4th, 2008, 7:27 pm
Posts: 24
Location: China
I want the computer to be closed at 2 am everyday and until 6 or 7 am no one could open it again cause they use my computer at night and I can not fall in sleep easily. So please help me!

[ Moderator!: [b/b] tag removed ]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 25th, 2008, 6:37 pm 
Offline

Joined: April 18th, 2008, 7:57 am
Posts: 1390
Location: The Interwebs
Unfortunately, under the features pending implementation:
The Manual wrote:
Add scheduling by extending SetTimer, e.g. daily at a certain time, etc.

Meaning that currently we do not have that feature. I have a couple of features that I simply use SetTimer checking the time to decide whether or not they activate, which as far as I know is the only current way.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 25th, 2008, 7:25 pm 
If you don“t want to use SetTimer,
you could try out the task-scheduler of windows.

More Info:
http://www.autohotkey.com/forum/topic29640.html&highlight=schedule+task
http://www.autohotkey.com/forum/topic21890.html&highlight=schedule+task


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 26th, 2008, 6:20 am 
Something like this should work, as long as you start it before midnight on the day you want it to do something.
Code:
Time = 2:00 ; time - HH24:MM

T := 86400 - (SubStr(A_Now,-5,2)*60 + SubStr(A_Now,-3,2))*60 + SubStr(A_Now,-1,2) + (RegExReplace(Time,"^[0-9]{1,2}:([0-9]{2})$","$1") + RegExReplace(Time,"^([0-9]{1,2}):[0-9]{2}$","$1")*60)*60

SetTimer, DoSomething, % T*1000 ; DoSomething at "Time"


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 26th, 2008, 6:58 pm 
Offline

Joined: April 4th, 2008, 7:27 pm
Posts: 24
Location: China
Krogdor wrote:
Unfortunately, under the features pending implementation:
The Manual wrote:
Add scheduling by extending SetTimer, e.g. daily at a certain time, etc.

Meaning that currently we do not have that feature. I have a couple of features that I simply use SetTimer checking the time to decide whether or not they activate, which as far as I know is the only current way.
Could it can pass the first time to run?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 26th, 2008, 7:02 pm 
Offline

Joined: April 4th, 2008, 7:27 pm
Posts: 24
Location: China
Anonymous wrote:
Something like this should work, as long as you start it before midnight on the day you want it to do something.
Code:
Time = 2:00 ; time - HH24:MM

T := 86400 - (SubStr(A_Now,-5,2)*60 + SubStr(A_Now,-3,2))*60 + SubStr(A_Now,-1,2) + (RegExReplace(Time,"^[0-9]{1,2}:([0-9]{2})$","$1") + RegExReplace(Time,"^([0-9]{1,2}):[0-9]{2}$","$1")*60)*60

SetTimer, DoSomething, % T*1000 ; DoSomething at "Time"
Who are you body? That's exactly what I want and qqq so much!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 26th, 2008, 7:10 pm 
Offline

Joined: April 4th, 2008, 7:27 pm
Posts: 24
Location: China
Code:
StringMid,MC,A_Now,11,2
StringMid,HC,A_Now,9,2
DL := (60-MC+(25-HC)*60)*60000
If (A_Hour > 1 And A_Hour < 7)
{
   Shutdown 5
}
Sleep %DL%
Shutdown 5
Now I use such code and it works well.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 20th, 2011, 4:13 pm 
based on some code I found in this thread, I created my own timer: if you specify a time in the future, it will count down to that time and launch. If you specify a time already passed for today, it will add 24hours so it can run at the specified time tomorrow.

Code:
; Time Registration
#Persistent
#SingleInstance,force

REGISTER_FUTURE:
TNowHour := SubStr(A_Now,-5,2)
TNowMin := SubStr(A_Now,-3,2)
TNowSec := SubStr(A_Now,-1,2)
TNowInSec := ((TNowHour*60 + TNowMin) * 60 + TNowSec)

TParamHour := RegExReplace(timeParam,"^([0-9]{1,2}):[0-9]{2}$","$1")
TParamMin := RegExReplace(timeParam,"^[0-9]{1,2}:([0-9]{2})$","$1")
TParamInSec := (TParamHour*60 + TParamMin) * 60

delayInSec := 0

If (TParamInSec > TNowInSec) {
   ;now : 9u00
   ;to run: 9u05
   ;delay = 5min = 9u05 - 9u00
   delayInSec := TParamInSec - TNowInSec
} else {
   ; now : 9u05
   ; to run: 9u00
   ; delay = 24u - 5min = 86400 sec - (9u05 - 9u00)   
   delayInSec := 86400 - ( TNowInSec - TParamInSec)
}

SetTimer, REGISTER_NOW, % delayInSec*-1000 ; convert to millisec and  make negative to denote only run once
TrayTip, Timer configured, Start in %delayInSec%sec at %TParamHour%:%TParamMin%
;MsgBox Timer configured in: %delayInSec% sec at %TParamHour%:%TParamMin%
return

DISABLE_FUTURE:
SetTimer, REGISTER_NOW, Off
return


REGISTER_NOW:
;add code to be executed at exact time you provided
return


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 20th, 2011, 4:16 pm 
in my previous post, I should have added:
timeParam should contain the exact time at witch the timer should be exectued, in format HH:MM


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 3rd, 2011, 3:30 pm 
I'm trying to run this modified timer, but setting timeParam doesn't seem to work right. The way I interpret your instructions, I should put a time like 19:45, or like 1945, or maybe like 19.45. I tried the former and got the error that a ":" is missing its "?". It accepted times of the form '0600', or '0'.

But then with a time that is supposed to be 1 minute in the future, it says the alarm will go off in "218846 seconds" at "0604:0604". Same issue with "06.33:06.33".


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 5th, 2011, 4:35 am 
Code:
error :=  19:45  ; Invalid - two numbers separated by : operator.
okay  := "19:45" ; Quoted string in an expression.
okay   =  19:45  ; Literal (non-expression) assignment.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 5th, 2011, 10:16 am 
Thanks for the explanation!


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: migz99, sjc1000, Yahoo [Bot] and 68 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