AutoHotkey Community

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

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: March 21st, 2008, 11:32 am 
This is my contribution to the fight against excessive power consumption.

The following command line triggers my script to start at 10pm each night.

Code:
AT 22:00 /Every:M,T,W,Th,F,S,Su START Shutdown.ahk /d C:\Users\Use
r\Documents


A tooltip is displayed and moves around the screen to alert the user that the computer is scheduled to shut down. The user then has 5 minutes to move the mouse, or to press a key before the computer shuts down. If the user does press a key or move the move, a 15minute timer begins before the tooltips reappear and the 5 minute countdown starts.

Code:
Gosub, SetTimer

SetTimer:

SetTimer, SetTimer, Off
SetTimer, Tooltip, 3000

Tooltip:
CoordMode, ToolTip, Screen
n++
Random, xm, 1, 1000
Random, ym, 1, 500
MousegetPos, X, Y
Tooltip, `n`n This system is scheduled to shut down. Press any key to abort.`n`n., %xm%,%ym%
Sleep, 3000
MousegetPos, Xn, Xn
If n = 100
GoSub, Shutdown
If (Abs(X - Xn) > 30 || Abs(Y - Yn) > 30)
Gosub, Another15
Return

Another15:
Tooltip
SetTimer, ToolTip, Off
n = 0
SetTimer, SetTimer, 900000
return

Shutdown:
Shutdown, 1
return

~a::
~b::
~c::
~d::
~e::
~f::
~g::
~h::
~i::
~j::
~k::
~l::
~m::
~n::
~o::
~p::
~q::
~r::
~s::
~t::
~u::
~v::
~w::
~x::
~y::
~z::
~Space::
~Enter::
~Esc::
~BS::
~Del::
~Ins::
~Home::
~End::
~PgUp::
~PgDn::
~Up::
~Down::
~Left::
~Right::
~ScrollLock::
~CapsLock::
~NumLock::
~1::
~2::
~3::
~4::
~5::
~6::
~7::
~8::
~9::
~0::
GoSub, Another15
return


I apologize if my code is difficult to read; I intended this for personal use and only publish it as an afterthought. Thanks to Delta for his Tooltip dictionary from which i derived my mouse movement 'hotkey.'

If there is a nicer way of doing "any key press", i would appreciate the help.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 21st, 2008, 3:44 pm 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
how? detect if ANY key is pressed


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 22nd, 2008, 1:46 pm 
Tyvm Jaco. That certainly tidies things up a lot.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 22nd, 2008, 2:01 pm 
A_TimeIdle is great.

Code now looks like this:

Code:
Gosub, SetTimer

SetTimer:

SetTimer, SetTimer, Off
SetTimer, Tooltip, 3000
Return

Tooltip:

CoordMode, ToolTip, Screen
IfGreater, A_TimeIdle, 600000,
GoSub, Shutdown
IfLess, A_TimeIdle, 300000
Gosub, Another15
Random, xm, 1, 1000
Random, ym, 1, 500
Tooltip, `n`n This system is scheduled to shut down. Press any key to abort.`n`n., %xm%,%ym%
Sleep, 3000
Return

Another15:
Tooltip
SetTimer, ToolTip, Off
SetTimer, SetTimer, 900000
return

Shutdown:
Shutdown, 1
return


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: sks and 21 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