AutoHotkey Community

It is currently May 27th, 2012, 10:22 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 27 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: February 4th, 2005, 12:45 am 
Offline

Joined: January 29th, 2005, 6:58 pm
Posts: 22
I was asked by some people to write a little AHK script that switchs the connected displays into power safe mode immediately (as it will be switched by the energy timeout).

I think this is a very good feature: Perhaps if you know that you are going to leave your system for 2 hours you will can press the hotkey to suspend your displays immediately (instead of waiting for the timeout).

Is there any message to send or a rundll32 function to trigger?

Thanks in advance for any hint.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 4th, 2005, 12:54 am 
Maybe not with plain AHK - but AHK+Comandiux could be an option [more...]
/MOFF! - Turn Monitor OFF. Use Carefully!
/MON! - Turn Monitor ON


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 4th, 2005, 7:09 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Here is a cruder method, partially tested on XP, that also takes 1 minute to go into effect:
Code:
#s::  ; Win+S
IfWinNotExist, Power Options Properties
   Run control.exe powercfg.cpl
WinWait, Power Options Properties,, 10
if ErrorLevel <> 0
   return
WinActivate
WinWaitActive
Control, ChooseString, After 1 min, ComboBox2  ; Turn off monitor in 1 minute.
Send !a  ; Apply
Sleep 60000  ; Wait for it to go into effect.
Loop  ; Wait for user to return
{
    Sleep, 100
    if A_IdleTime < 500
        break
}
IfWinNotExist  ; "last found" window
    return
WinActivate
Control, ChooseString, After 10 mins, ComboBox2  ; Adjust to for your prefs.
Send {Enter}
return
Maybe there's a better way with RunDLL32.exe or PostMessage. Or just use a nice command line utility such as the one BoBo posted.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 4th, 2005, 8:16 am 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2545
This works ok :).

Code:
; Turn Monitor Off
SendMessage, 0x112, 0xF170, 2,, Program Manager   

Sleep 4000

; Turn Monitor On
SendMessage, 0x112, 0xF170, -1,, Program Manager 

; (2 = off, 1 = standby, -1 = on)
 


API call:
To turn off the monitor:
SendMessage(AnyForm.hwnd, WM_SYSCOMMAND, SC_MONITORPOWER, 2)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 4th, 2005, 9:26 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
That's much nicer. Thanks for sharing this discovery.

I checked if there was a similar one to spin down hard disks, but didn't find one. I guess you wouldn't want to anyway, since it would spin down your boot drive too, which would almost certainly have to spin right up again.

Here is the relevant page at MSDN.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 4th, 2005, 9:28 am 
MonSwitch.exe

Code:
If 1 in D,/D,Down,/Down ; Turn Monitor Off/Down
      SendMessage, 0x112, 0xF170, 2,, Program Manager   

If 1 in U,/U,Up,/Up ; Turn Monitor On/Up
      SendMessage, 0x112, 0xF170, -1,, Program Manager

If 1 in I,/I,Idle,/Idle ; Turn Monitor Standby/Idle
      SendMessage, 0x112, 0xF170, 1,, Program Manager

; (2 = off, 1 = standby, -1 = on)


Code:
Run, %COMSPEC% /C MonSwitch.exe /I ,, Hide
Cool, but untested. :lol:


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 4th, 2005, 9:29 am 
:shock:
Quote:
Run, %COMSPEC% /C MonSwitch.exe /I ,, Hide
:roll:


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 4th, 2005, 10:26 am 
Offline

Joined: January 29th, 2005, 6:58 pm
Posts: 22
corrupt wrote:
This works ok :).


Unfortunately this doesn't work here. The display flickers shortly and then the image appears again.

Should this work exactly like the power management service (if you move the mouse or press a key the system wakes up) or does it forcly switch off the screen?

I think the input aware feature of windows is done by the screensaver service.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 4th, 2005, 11:03 am 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2545
The code I provided should turn the monitor off for 4 seconds then turn it back on to demonstrate.

Yes, moving the mouse, hitting a key on the keyboard, etc... should turn the monitor back on.

Does this turn your monitor off if you don't move your mouse and/or press keys ?

Code:
 SendMessage, 0x112, 0xF170, 2,, Program Manager


Report this post
Top
 Profile  
Reply with quote  
 Post subject: doesn't "stick"
PostPosted: February 4th, 2005, 12:33 pm 
Offline

Joined: April 23rd, 2004, 4:38 am
Posts: 34
Location: Adelaide, South Australia
I have the same problem, the monitor immediately comes back on.

I have added the off and on commands to hotkeys (also tried the standby)...

Code:
^!0::SendMessage, 0x112, 0xF170, 2,, Program Manager  ; Turn Monitor Off
^!1::SendMessage, 0x112, 0xF170, -1,, Program Manager ; Turn Monitor On
^!2::SendMessage, 0x112, 0xF170, 1,, Program Manager  ; Turn Monitor to Standby


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 4th, 2005, 1:44 pm 
Offline

Joined: January 29th, 2005, 6:58 pm
Posts: 22
corrupt wrote:
Does this turn your monitor off if you don't move your mouse and/or press keys ?


Sorry my fault. The release event of the hotkey switches the displays on immediately. So I have to wait for the release before I will switch them off.

Now it works perfectly. Many thanks for this cool hint.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 4th, 2005, 3:19 pm 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2545
Glad to hear that you got it working :).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 26th, 2007, 4:25 pm 
Chris wrote:
Here is a cruder method, partially tested on XP, that also takes 1 minute to go into effect:
Code:
#s::  ; Win+S
IfWinNotExist, Power Options Properties
   Run control.exe powercfg.cpl
WinWait, Power Options Properties,, 10
if ErrorLevel <> 0
   return
WinActivate
WinWaitActive
Control, ChooseString, After 1 min, ComboBox2  ; Turn off monitor in 1 minute.
Send !a  ; Apply
Sleep 60000  ; Wait for it to go into effect.
Loop  ; Wait for user to return
{
    Sleep, 100
    if A_IdleTime < 500
        break
}
IfWinNotExist  ; "last found" window
    return
WinActivate
Control, ChooseString, After 10 mins, ComboBox2  ; Adjust to for your prefs.
Send {Enter}
return
Maybe there's a better way with RunDLL32.exe or PostMessage. Or just use a nice command line utility such as the one BoBo posted.


Is there a more direct way to switch to "After 1 min" without having to actually open the powercfg.cpl? I'd like a hotkey to toggle between "After 1 min" and "never", but would like it to not have to open the window, just apply the settings change.


Report this post
Top
  
Reply with quote  
 Post subject: this works..
PostPosted: May 24th, 2007, 10:06 am 
if you put a sleep before the sendmessage the monitor goes to sleep without being powered on emediately.

f1::
sleep 1000
SendMessage, 0x112, 0xF170, 1,, Program Manager
return


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 4th, 2007, 10:46 am 
Is there way to turn on display by specific key, not by any key?


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 27 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], BrandonHotkey, chaosad, robotkoer and 64 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