Jump to content

Recommended Posts

Posted (edited)

Hello :bye:

This is a simple script but serves its purpose to me and since I thought it was neat I thought that I might as well share it.

Time to explain the purpose of this script. My bedroom unfortunately does not have a light although I do have lamps I don't use them while I am sleeping. So what I have been doing is keeping one of my monitors on every night and I started to get tired of having to push the button to turn it on/off everynight. This script fixes that problem ^_^

#include <Misc.au3>
#include <Timers.au3>
#include <Constants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

_Singleton(@ScriptName)

Opt("TrayMenuMode", 1)
Opt("TrayOnEventMode", 1)

$GUI = GUICreate("Monitor Sleep", 200, 130, Default, Default, $WS_DLGFRAME)
GUICtrlCreateLabel("Monitor to Sleep", 0, 0, 200, 20)
$Mon_0 = GUICtrlCreateRadio("All", 0, 20, 60, 20)
$Mon_1 = GUICtrlCreateRadio("Internal", 60, 20, 60, 20)
$Mon_2 = GUICtrlCreateRadio("External", 120, 20, 60, 20)
GUICtrlCreateLabel("Monitor Sleep Delay", 0, 40, 200, 20)
$Mon_Sleep = GUICtrlCreateCombo("1", 0, 60, 200, 20, $CBS_DROPDOWNLIST)
GUICtrlSetData(-1 , "5|10|20|30|40|50|60")
$Start = GUICtrlCreateButton("Run", 0,  85, 100, 20)
$Exit = GUICtrlCreateButton("Exit", 100,  85, 100, 20)
GUICtrlSetState($Mon_0, $GUI_CHECKED)
TraySetOnEvent($TRAY_EVENT_PRIMARYDOWN, "_Tray")
GUISetState(@SW_SHOW)

$Loop = 0
$Toggle = 0

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Exit
            Exit
        Case $Start
            If GUICtrlRead($Start) = "Run" Then
                $Loop = 0
                $Toggle = 1
                GUISetState(@SW_HIDE)
                GUICtrlSetData($Start, "Stop")
                GUICtrlSetState($Mon_0, $GUI_DISABLE)
                GUICtrlSetState($Mon_1, $GUI_DISABLE)
                GUICtrlSetState($Mon_2, $GUI_DISABLE)
                GUICtrlSetState($Mon_Sleep, $GUI_DISABLE)
            ElseIf GUICtrlRead($Start) = "Stop" Then
                $Loop = 0
                $Toggle = 0
                GUICtrlSetData($Start, "Run")
                GUICtrlSetState($Mon_0, $GUI_ENABLE)
                GUICtrlSetState($Mon_1, $GUI_ENABLE)
                GUICtrlSetState($Mon_2, $GUI_ENABLE)
                GUICtrlSetState($Mon_Sleep, $GUI_ENABLE)
            EndIf
    EndSwitch
    $Executable = "DisplaySwitch.exe"
    If $Toggle = 1 Then
        $Idle = GUICtrlRead($Mon_Sleep) * 60000
        If $Loop = 0 Then
        If _Timer_GetIdleTime() >= $Idle Then
            If GUICtrlRead($Mon_0) = 1 Then
                $Loop = 1
                Opt("WinTitleMatchMode", 4)
                $Progman = WinGetHandle("Classname=Progman")
                DllCall("user32.dll", "int", "SendMessage", "hwnd", $Progman, "int", 274, "int", 61808, "int", 2)
            ElseIf GUICtrlRead($Mon_1) = 1 Then
                $Loop = 1
                ShellExecute($Executable, "/External") ; Executes External causing Internal to sleep!
            ElseIf GUICtrlRead($Mon_2) = 1 Then
                $Loop = 1
                ShellExecute($Executable, "/Internal") ; Executes Internal causing External to sleep!
            EndIf
        EndIf
    EndIf
EndIf
If _Timer_GetIdleTime() = 0 And $Loop = 1 Then
    $Loop = 0
    ShellExecute($Executable, "/Extend")
EndIf
WEnd

Func _Tray()
    GUISetState(@SW_SHOW)
EndFunc
Edited by SkellySoul
Posted

Does monitor light scare away raccoons or something?

I'm sure the script will be useful to someone, but I'm intrigued as to why you need a monitor light

while sleeping.

Well if I wake up in the middle of the night I usually end up tripping over something or not knowing where I am.

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...