Jump to content
Sign in to follow this  
NileshSutar

monitor turn off

Recommended Posts

NileshSutar

;#NoTrayIcon

Global Const $lciWM_SYSCommand = 274
Global Const $lciSC_MonitorPower = 61808
Global Const $lciPower_Off = 2
Global Const $lciPower_On = -1

Global $MonitorIsOff = False

HotKeySet("{F11}", "_Monitor_OFF")
HotKeySet("{F10}", "_Monitor_ON")
HotKeySet("{Esc}", "_Quit")


While 1
    Sleep(10)
WEnd

Func _Monitor_ON()
    $MonitorIsOff = False
    Local $Progman_hwnd = WinGetHandle('[CLASS:Progman]')
    
    DllCall('user32.dll', 'int', 'SendMessage', _
                                                'hwnd', $Progman_hwnd, _
                                                'int', $lciWM_SYSCommand, _
                                                'int', $lciSC_MonitorPower, _
                                                'int', $lciPower_On)
EndFunc

Func _Monitor_OFF()
    $MonitorIsOff = True
    Local $Progman_hwnd = WinGetHandle('[CLASS:Progman]')
    
    While $MonitorIsOff = True
        DllCall('user32.dll', 'int', 'SendMessage', _
                                                    'hwnd', $Progman_hwnd, _
                                                    'int', $lciWM_SYSCommand, _
                                                    'int', $lciSC_MonitorPower, _
                                                    'int', $lciPower_Off)
        _IdleWaitCommit(0)
        Sleep(20)
    WEnd
EndFunc

Func _IdleWaitCommit($idlesec)
    Local $iSave, $LastInputInfo = DllStructCreate ("uint;dword")
    DllStructSetData ($LastInputInfo, 1, DllStructGetSize ($LastInputInfo))
    DllCall ("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr ($LastInputInfo))
    Do
        $iSave = DllStructGetData ($LastInputInfo, 2)
        Sleep(60)
        DllCall ("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr ($LastInputInfo))
    Until (DllStructGetData ($LastInputInfo, 2)-$iSave) > $idlesec Or $MonitorIsOff = False
    Return DllStructGetData ($LastInputInfo, 2)-$iSave
EndFunc

Func _Quit()
    _Monitor_ON()
    Exit
EndFunc

i want my monitor to go to sleep as long as i press any hotkey to wake up it.The movement of mouse should not wake it up.

so got the above code.I want it to be able to be called in my other scripts.How to do that?plz help

Edited by NileshSutar

Share this post


Link to post
Share on other sites
Kidney

you will need to use the #include

you will get the file name of the code you have posted above and do the include in your other script.

 

lets say the file name of the above code is "MonitorSwitch.au3"

you will need to include that file like so:

#include <MonitorSwitch.au3>

This will allow you to call the functions: _Monitor_ON(), _Monitor_OFF(), _IdleWaitCommit(), and _Quit()

all of which are located in the MonitorSwitch.au3 file, not the main script

however, including the file will not run it. it will simple allow the main script to use the functions defined in the MonitorSwitch.au3

this means that your hotkeys will not work unless placed inside of the main script

Edited by Kidney

Share this post


Link to post
Share on other sites
NileshSutar

 

however, including the file will not run it. it will simple allow the main script to use the functions defined in the MonitorSwitch.au3

this means that your hotkeys will not work unless placed inside of the main script

Yes i did include the file in my main script.But when i ran my main script only the above script  ran(i.e monitor turn off) and the rest of my main script did not.Why??Also i can use the hot keys even when they are not included in the main script.

Edited by NileshSutar

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  

×