Jump to content

Recommended Posts

Posted

Nothing special I made a tray program for my friend so his monitor will turn off after a set time then turn back on after another time.

Here is the Monitor control part:

Opt("WinTitleMatchMode", 4)

Monitor("off")

Func Monitor($io_control = "on")
    Local $WM_SYSCommand = 274
    Local $SC_MonitorPower = 61808
    Local $HWND = WinGetHandle("classname=Progman")
    Switch StringUpper($io_control)
        Case "OFF"
            DllCall("user32.dll", "int", "SendMessage", "hwnd", $HWND, "int", $WM_SYSCommand, "int", $SC_MonitorPower, "int", 2)
        Case "ON"
            DllCall("user32.dll", "int", "SendMessage", "hwnd", $HWND, "int", $WM_SYSCommand, "int", $SC_MonitorPower, "int", -1)
        Case Else
            MsgBox(32, @ScriptName, "Command usage: on/off")
    EndSwitch
EndFunc

The commands were from the feature request, I just made it into a function. :)

Posted

it's a great function :) , i realy think i wil need this function.

do you think you can make a function to chek if the monitor is off or on??

keep up the good work :)

  • 1 year later...
Posted (edited)

Hey, great function James. I hope you don't mind, but I added the "powersave" functionality, along with turning on the screensaver.

;===============================================================================
; Function Name:   _Monitor()
; Description:   Changes the state of the monitor or turns on screensaver.
; Syntax:         _Monitor ( [$sIo_control] )
;
; Parameter(s): $sIo_control = The command to send (default = "on").
;                 "on" turns on monitor.
;                 "off" turns off monitor.
;                 "powersave" puts monitor(s) in powersave mode.
;                  "screensaver" turns on screensaver, if one has been selected in Windows.
;
; Requirement(s):  External:   = user32.dll (it's already in system32).
;                 Internal:   = None.
;
; Author(s):       Original function by JamesBrooks (on/off). Modified by TrystianSky (added powersave/screensaver).
;
; Example(s):
;   _Monitor("powersave")
;===============================================================================

Func _Monitor($sIo_control = "on")
    Local $iWM_SYSCommand = 274
    Local $iSC_MonitorPower = 61808
    Local $iSC_ScreenSave = 61760
    Local $hWnd = WinGetHandle("[CLASS:Progman]")
    Switch StringUpper($sIo_control)
        Case "OFF"
            DllCall("user32.dll", "int", "SendMessage", "hwnd", $hWnd, "int", $iWM_SYSCommand, "int", $iSC_MonitorPower, "int", 2)
        Case "ON"
            DllCall("user32.dll", "int", "SendMessage", "hwnd", $hWnd, "int", $iWM_SYSCommand, "int", $iSC_MonitorPower, "int", -1)
        Case "POWERSAVE"
            DllCall("user32.dll", "int", "SendMessage", "hwnd", $hWnd, "int", $iWM_SYSCommand, "int", $iSC_MonitorPower, "int", 1)
        Case "SCREENSAVER"
            DllCall("user32.dll", "int", "SendMessage", "hwnd", $hWnd, "int", $iWM_SYSCommand, "int", $iSC_ScreenSave, "int", 0)
        Case Else
            MsgBox(64, @ScriptName, "Command usage: on/off/powersave/screensaver")
    EndSwitch

EndFunc;==>_Monitor

Edit: Changed WinGetHandle call. Thanks Authenticity.

Edited by TrystianSky
Posted

Hey, great function James. I hope you don't mind, but I added the "powersave" functionality, along with turning on the screensaver.

;===============================================================================
; Function Name:   _Monitor()
; Description:   Changes the state of the monitor or turns on screensaver.
; Syntax:         _Monitor ( [$sIo_control] )
;
; Parameter(s): $sIo_control = The command to send (default = "on").
;                 "on" turns on monitor.
;                 "off" turns off monitor.
;                 "powersave" puts monitor(s) in powersave mode.
;                  "screensaver" turns on screensaver, if one has been selected in Windows.
;
; Requirement(s):  External:   = user32.dll (it's already in system32).
;                 Internal:   = None.
;
; Author(s):       Original function by JamesBrooks (on/off). Modified by TrystianSky (added powersave/screensaver).
;
; Example(s):
;   _Monitor("powersave")
;===============================================================================

Func _Monitor($sIo_control = "on")
    Local $iWM_SYSCommand = 274
    Local $iSC_MonitorPower = 61808
    Local $iSC_ScreenSave = 61760
    Local $hWnd = WinGetHandle("classname=Progman")
    Local $iRet = 1
    Switch StringUpper($sIo_control)
        Case "OFF"
            DllCall("user32.dll", "int", "SendMessage", "hwnd", $hWnd, "int", $iWM_SYSCommand, "int", $iSC_MonitorPower, "int", 2)
        Case "ON"
            DllCall("user32.dll", "int", "SendMessage", "hwnd", $hWnd, "int", $iWM_SYSCommand, "int", $iSC_MonitorPower, "int", -1)
        Case "POWERSAVE"
            DllCall("user32.dll", "int", "SendMessage", "hwnd", $hWnd, "int", $iWM_SYSCommand, "int", $iSC_MonitorPower, "int", 1)
        Case "SCREENSAVER"
            DllCall("user32.dll", "int", "SendMessage", "hwnd", $hWnd, "int", $iWM_SYSCommand, "int", $iSC_ScreenSave, "int", 0)
        Case Else
            MsgBox(64, @ScriptName, "Command usage: on/off/powersave/screensaver")
    EndSwitch

EndFunc ;==>_Monitor
nothing happens on my monitor with any of the parameters.

I'm using WinXP SP3 and AI 3

Posted

Either insert in the header Opt("WinTitleMatchMode", 4) or change WinGetHandle("classname=Progman") to WinGetHandle("[CLASS:Progman]")

Great call! Works beautifully now. Thanks fro the help.
Posted

Thanks for the feedback dmob. I forgot to change the winhandle call.

Either insert in the header Opt("WinTitleMatchMode", 4) or change WinGetHandle("classname=Progman") to WinGetHandle("[CLASS:Progman]")

Thanks Authenticity. Decided to use WinGetHandle("[CLASS:Progman]") instead of Opt("WinTitleMatchMode", 4) to make the function play well with other functions. =)
Posted

guys, can we add wake on hot key support?

i mean can this work like a pc on monitor off mode, a mouse movement or keyboard sroke will wake up the monitor?

Of course.

HotKeySet("!{F7}", "On")
HotKeySet("!{F7}", "Off")

While 1
    Sleep(500)
Wend

Func Off()
    _Monitor("off")
EndFunc

Func On()
    _Monitor()
EndFunc

Func _Monitor($sIo_control = "on")
    Local $iWM_SYSCommand = 274
    Local $iSC_MonitorPower = 61808
    Local $iSC_ScreenSave = 61760
    Local $hWnd = WinGetHandle("[CLASS:Progman]")
    Switch StringUpper($sIo_control)
        Case "OFF"
            DllCall("user32.dll", "int", "SendMessage", "hwnd", $hWnd, "int", $iWM_SYSCommand, "int", $iSC_MonitorPower, "int", 2)
        Case "ON"
            DllCall("user32.dll", "int", "SendMessage", "hwnd", $hWnd, "int", $iWM_SYSCommand, "int", $iSC_MonitorPower, "int", -1)
        Case "POWERSAVE"
            DllCall("user32.dll", "int", "SendMessage", "hwnd", $hWnd, "int", $iWM_SYSCommand, "int", $iSC_MonitorPower, "int", 1)
        Case "SCREENSAVER"
            DllCall("user32.dll", "int", "SendMessage", "hwnd", $hWnd, "int", $iWM_SYSCommand, "int", $iSC_ScreenSave, "int", 0)
        Case Else
            MsgBox(64, @ScriptName, "Command usage: on/off/powersave/screensaver")
    EndSwitch

EndFunc;==>_Monitor
Posted

If you have dual (or more) monitors, can you control each of them individually? Like make the secondary one powersave after 5mins of inactivity and leave the primary one alone.

  • 2 weeks later...
Posted

Hello,

if I run the script part from Post#1

it switches the monitor "Off".

But if I move the mouse, the monitor switches "On".

I want, that the monitor remains in "Off"- status and switches "On"

if I push a key or a mouse button.

If I run the script part from Post#15 and push "Alt"+"F7"

the monitor switches "Off" for a second, then switches "On".

It should show the same behavior as I wrote before.

I don't know, how to realize this in a script.

I want this for my notebook (laptop),

which has no switch to turn off the display.

Can anybody help me please?

Perhaps the author?

Thanks :)

  • 4 weeks later...
Posted

Hello. anyone can add a handle or something to select which monitor to turn off (primary secondary)

What I should look to change it?

I want to make a camera controled powersave mode. I have made the camera/motion detect issue, but I don't know anything about the monitor :D

Posted

Hello. anyone can add a handle or something to select which monitor to turn off (primary secondary)

What I should look to change it?

I want to make a camera controled powersave mode. I have made the camera/motion detect issue, but I don't know anything about the monitor :D

Hmm, I never thought about multi monitors. I'll take a look around.
  • 3 years later...

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...