Jump to content
Sign in to follow this  
Achilles

Sleeping in a not so sleepy way

Recommended Posts

Alright, I have a program that will shutoff your computer when the time you input is up. Soooo, lets say I say Sleep(3600000), which is one hour. The GuiBox that I create this all in is still there. However if I want to cancel it I have to right click on the tray icon and exit. The normal "X" doesn't do anything because the script is sleeping. Is there a simple way of doing this?

I say simple because I know I could do a Do.. Until thing but that would involve adding 60000 every minute passes and I was wondering if tehre was a simpler way.

Share this post


Link to post
Share on other sites

I'd just change the way I'm doing it...

Global $StartTimer, $ExitHour, $ExitMin
$gui = GUICreate('shutdown', 220, 80)
GUICtrlCreateLabel('Hour:', 10, 15, 40, 20, 0x01)
$hour = GUICtrlCreateInput('', 50, 10, 50, 20)
GUICtrlCreateLabel('Min:', 110, 15, 40, 20, 0x01)
$min = GUICtrlCreateInput('', 150, 10, 50, 20)
$button = GUICtrlCreateButton('Start|Stop', 75, 40, 60, 30)
GUISetState()
While 1
    Switch GUIGetMsg()
        Case -3
            Exit
        Case $button
            $ExitHour = GUICtrlRead($hour)
            $ExitMin = GUICtrlRead($min)
            If $ExitHour <> '' And $ExitMin <> '' Then _
                $StartTimer = Not $StartTimer
    EndSwitch
    If $StartTimer Then
        If @HOUR = $ExitHour And @MIN = $ExitMin Then Shutdown(1)
    EndIf
WEnd
And set it for a specific time...


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

How about:

Global $Minutes = 60

$Minutes = $Minutes * 60000

$Main_Timer = TimerInit()

While TimerDiff($Main_Timer) < $Minutes
    
    If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit
    
    Sleep(1)
WEnd

; Shutdown code

Hallman

Thanks! Thats what I was looking for...

@Smoke_N: I was thinking about doing that because in my program you can also insert the time but I decided I would try something different :) Thanks for the help though, I learned a few things from the way you did that short example...

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...