AutoHotkey Community

It is currently May 24th, 2012, 9:50 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: November 16th, 2006, 3:39 am 
@Boskoop
@all

Boskoop originally posted this code to resume from suspend at a certain time. It works perfectly in xp, but in 98 it executes the code after the line:
Code:
WakeUp(Year, Month, Day, Hour, Minute, Hibernate, Resume, Name)
immediately - with no timed delay. Anyone have any ideas?

Thanks, Micahs

Here is the code again. For testing purposes I added some code to set the target date 1 minute into the future.

Code:
; CONFIGURATION
Year=2006
Month=11    ;1-12
Day=14      ;1-31
Hour=21     ;0-23
Minute=16   ;1-59
Hibernate=0 ;0, 1, 2
Resume=1    ;0,1
Name=%A_Now%

;***********************added for testing
EnvAdd,Name,1,Minutes
StringMid,Year,Name,1,4
StringMid,Month,Name,5,2
StringMid,Day,Name,7,2
StringMid,Hour,Name,9,2
StringMid,Minute,Name,11,2
;msgbox, %Name%`n%Year%-%Month%-%Day%-%Hour%-%Minute%
;*************************************

; AUTOEXECUTE
WakeUp(Year, Month, Day, Hour, Minute, Hibernate, Resume, Name)

msgbox, I'm awake and working!


; FUNCTIONS
WakeUp(Year, Month, Day, Hour, Minute, Hibernate, Resume, Name)
;Awaits duetime, then returns to the caller (like some sort of "sleep until duetime").
;If the computer is in hibernate or suspend mode
;at duetime, it will be reactivated (hardware support provided)
;Parameters: Year, Month, Day, Hour, Minute together produce duetime
;Hibernate: If Hibernate=1, the function hibernates the computer. If Hibernate=2 the computer is set to
;         suspend-mode
;Resume: If Resume=1, the system is restored from power save mode at due time
;Name: Arbitrary name for the timer
{
    duetime:=GetUTCFileTime(Year, Month, Day, Hour, Minute)

    Handle:=DLLCall("CreateWaitableTimer"
            ,"char *", 0
            ,"Int",0
            ,"Str",name, "UInt")

    DLLCall("CancelWaitableTimer","UInt",handle)

    DLLCall("SetWaitableTimer"
          ,"Uint", handle
          ,"Int64*", duetime        ;duetime must be in UTC-file-time format!
          ,"Int", 1000
          ,"Uint",0
          ,"Uint",0
          ,"Int",resume)


    ;Hibernates the computer, depending on variable "Hibernate":
    If Hibernate=1       ;Hibernate
        {
        DllCall("PowrProf\SetSuspendState", "int", 1, "int", 0, "int", 0)
        }

    If Hibernate=2      ;Suspend
       {
       DllCall("PowrProf\SetSuspendState", "int", 0, "int", 0, "int", 0)
       }
    Signal:=DLLCall("WaitForSingleObject"
            ,"Uint", handle
            ,"Uint",-1)

    DllCall("CloseHandle", Uint, Handle)   ;Closes the handle

}


GetUTCFiletime(Year, Month, Day, Hour, Min)
;Converts "System Time" (readable time format) to "UTC File Time" (number of 100-nanosecond intervals since January 1, 1601 in  Coordinated Universal Time UTC)
{
    DayOfWeek=0

    Second=00
    Millisecond=00


    ;Converts System Time to Local File Time:
    VarSetCapacity(MyFiletime  , 64, 0)
    VarSetCapacity(MySystemtime, 32, 0)

    InsertInteger(Year,       MySystemtime,0)
    InsertInteger(Month,      MySystemtime,2)
    InsertInteger(DayOfWeek,  MySystemtime,4)
    InsertInteger(Day,        MySystemtime,6)
    InsertInteger(Hour,       MySystemtime,8)
    InsertInteger(Min,        MySystemtime,10)
    InsertInteger(Second,     MySystemtime,12)
    InsertInteger(Millisecond,MySystemtime,14)

    DllCall("SystemTimeToFileTime", Str, MySystemtime, UInt, &MyFiletime)
    LocalFiletime := ExtractInteger(MyFiletime, 0, false, 8)

    ;Converts local file time to a file time based on the Coordinated Universal Time (UTC):
    VarSetCapacity(MyUTCFiletime  , 64, 0)
    DllCall("LocalFileTimeToFileTime", Str, MyFiletime, UInt, &MyUTCFiletime)
    UTCFiletime := ExtractInteger(MyUTCFiletime, 0, false, 8)

    Return UTCFileTime
}


ExtractInteger(ByRef pSource, pOffset = 0, pIsSigned = false, pSize = 32)
; Documented in Autohotkey Help
{
    Loop %pSize%
        result += *(&pSource + pOffset + A_Index-1) << 8*(A_Index-1)
    if (!pIsSigned OR pSize > 4 OR result < 0x80000000)
        return result
    return -(0xFFFFFFFF - result + 1)
}



InsertInteger(pInteger, ByRef pDest, pOffset = 0, pSize = 4)
; Documentated in Autohotkey Help
{
  Loop %pSize%
          DllCall("RtlFillMemory", UInt, &pDest + pOffset + A_Index-1
                  , UInt, 1, UChar, pInteger >> 8*(A_Index-1) & 0xFF)
}


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 11th, 2007, 11:24 am 
Any idea how to schedule (eg. every Tuesday, 20:15-21:15 --> VCR) the above code?

Windows Scheduler?
The script as a service?

:?:


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 11th, 2007, 11:48 pm 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
MSDN wrote:
SetSuspendState: Client Requires Windows Vista, Windows XP, or Windows 2000 Professional.
Sic...

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 12th, 2007, 7:40 am 
Offline

Joined: December 1st, 2006, 9:27 am
Posts: 460
@PhiLho
Thanks for the reply! In my implementation, 'hibernate' is set to '0' so 'SetSuspendState' is never executed. It looks like it is 'SetWaitableTimer' that's not working - it just blows on past and doesn't wait like it should. In win98 that is. In XP it works great. MSDN states that 'SetWaitableTimer' will work in 98 with a unicode patch, but not for me. Oh well.
Just now, reading Boskoop's orig thread (http://www.autohotkey.com/forum/viewtopic.php?t=12281) I see
Quote:
Wake up from Hibernate requires hardware support for S4-mode
Hmm, maybe the 'puter I was using didn't support this.
[EDIT] - Again, Hmm. After reading Boskoop's latest post, my question has been answered.

@bobo
When I couldn't get it to work in win98 I stopped working on this, but now I'll post it for posterity.
Try this:
http://www.autohotkey.net/~Micahs/sndSched/sndSched.zip
Image
It lets you create timers that reprogram themselves for the next cycle after firing. It also lets you moniter and kill individual timers. I haven't cleaned this up or commented very thoroughly. Right now, it only supports Weekdays, Weekends, or Everyday. I was going to add specific days, but I stopped working on it. It won't take much to add that feature. Have fun!
[EDIT] - Also, it currently only plays sounds, but it shouldn't be hard to make it execute a program or such. (Or kill a program)
For VCR functionality, I would leave it the way it is for scheduling start time, and when it fires:
Code:
;call to sleep until awoken
WakeUp(YYYY, MM, DD, Hour, Min, Resume, Name)
;^sleeps for specified time^

;does this once it wakes up \/
;do stuff to start whatever I want

;use wakeup data to reconstruct start time
Start = %YYYY%%MM%%DD%%Hour%%Min%%Sec%

;create stop time in the YYYYMMDDHH24MISS format
Stop = %stopYYYY%%stopMM%%stopDD%%stopHour%%stopMin%%stopSec%

;get difference between start time and stop time in seconds
StartStopDiff := EnvSub, %Stop%, %Start%, Seconds

;set timer for desired stop time
SetTimer,stopIT,%StartStopDiff%

Return

stopIT:
   ;do stuff to stop whatever I started
   
   ;continue - If recurring, set for next time. If not, exit
    title=%newTitle%
    if(recurring=1)
   {   EnvAdd, Var, 1, Days
        gosub dateFixer
        gosub makeLNK
        goto reDeaux
   }
    else
   {   exitApp
   }
Return

You could stick this in the 'FirstCall.ahk' module replacing lines 44-69. This is untested, but looks ok. You just have to provide the 'Stop' data, maybe add another date-time picker section in the gui.
Of course, you'll have to make other changes too. :)

_________________
Image


Last edited by Micahs on March 12th, 2007, 9:59 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 12th, 2007, 8:39 am 
Image
Click it to get it :D


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 12th, 2007, 10:14 am 
Offline

Joined: December 1st, 2006, 9:27 am
Posts: 460
Erbärmlicher mann, ich sprechen Deutsch nicht! - FreeTranslation.com

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 12th, 2007, 10:45 am 
Quote:
Erbärmlicher mann
:shock:
Nice translation. :lol:

Sorry. FYI, I've linked that image just to show what I'm looking for. You must know that I didn't seen the image you've posted in advance. And I'm really sorry that the linked app/site is in German. Well, 80 Mill. Germans don't have a problem with that (and there's a bunch of people from Austria&Switzerland too :wink:) so it wasn't completely useless.

Anyway, thanks for your statement & support. 8)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 16th, 2007, 9:04 pm 
Offline

Joined: December 1st, 2006, 9:27 am
Posts: 460
Quote:
Nice translation.
Yeah, I translated it back to english and was amused by the results so I posted it anyway.
Quote:
80 Mill. Germans don't have a problem with that
Sorry, dude. Wasn't knockin' it...
Quote:
I didn't seen the image you've posted in advance
Yeah, I posted and then edited right after. Your post came right in the middle. Serves you right for being so efficient! :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 5th, 2007, 6:42 am 
Offline

Joined: December 1st, 2006, 9:27 am
Posts: 460
This has been solved (but still doesn't work). The "RtlFillMemory" function does not work in 98.

_________________
Image


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: azure, Blackholyman, BrandonHotkey, Cephei1, patgenn123, Xx7, 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