MrCreatoR

Monitor On/Off Example

29 posts in this topic

Hi all,

This example shows how you can turn off your monitor, so even mouse move can not turn it on back.

The main function to turn on/off monitor is taken from Help file example, and was changed for this example's needs.

The function _IdleWaitCommit() i think written by amel27, and also have been changed.

Here it is:

#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")

MsgBox(64, "Monitor On/Off", "Press F11 to turn off the monitor." & @LF & _
                            "Press F10 to turn on the monitor back." & @LF & _
                            "Press ESC to turn on the monitor and exit program.")

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

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites



Thanks, I was trying to do this, and i found here....

Share this post


Link to post
Share on other sites

Very Nice, but is it possible to auto turn off and auto tur on after like 3 seconds, i tried

send("{f11}")
sleep(3000)
send("{f10}")oÝ÷ Ù»­Ú'+n®w¡÷ÚÛazx­®'jëh×6send("{f11}")
sleep(3000)
_Monitor_OFF()

and still not worked, maybe you can help me?

Share this post


Link to post
Share on other sites

is it possible to auto turn off and auto tur on after like 3 seconds

You will need to change these functions a little:

While 1
    _Monitor_OFF() ;this will turn off monitor and sleep 3000
    _Monitor_ON()
    Sleep(3000)
WEnd

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

Func _IdleWaitCommit($idlesec, $TimerInit=-1)
    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))
        If $TimerInit <> -1 And TimerDiff($TimerInit) >= 3000 Then ExitLoop
    Until (DllStructGetData ($LastInputInfo, 2)-$iSave) > $idlesec Or $MonitorIsOff = False
    Return DllStructGetData ($LastInputInfo, 2)-$iSave
EndFunc

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

Strange... on my laptop it only disables the screen for a few seconds...

Share this post


Link to post
Share on other sites

sounds like a useful covert script...

Share this post


Link to post
Share on other sites

Strange... on my laptop it only disables the screen for a few seconds...

^^ Mine too. Any ideas?

Share this post


Link to post
Share on other sites

^^ Mine too. Any ideas?

If you read the script you will see that it only turns the monitor off for 3 seconds ( sleep(3000) ) before turning it back on.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

If you read the script you will see that it only turns the monitor off for 3 seconds ( sleep(3000) ) before turning it back on.

Sorry, I should have said... I'm trying to run the original script... the one without the sleep(3000) thing. I'm running XPsp2 on a laptop.

Share this post


Link to post
Share on other sites

On further investigation... if I've pressed F11, the monitor turns off for a second or so whenever I move the mouse or press a key. So the turning off thing isn't a problem. It's just that for some reason either my monitor keeps turning back on after a second or so. Curiouser and curiouser!

Share this post


Link to post
Share on other sites

@mdixon

What AutoIt version you are using? and what system?

And have you tried to play with other hotkeys? maybe some external app on your system (some forgotten AutoIt script?) hits the F10 hotkey? :)


Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

@mdixon

What AutoIt version you are using? and what system?

And have you tried to play with other hotkeys? maybe some external app on your system (some forgotten AutoIt script?) hits the F10 hotkey? :)

I'm using AutoIt v3.2 on an XP SP2 laptop (ASUS A6T).

I've tried with other hotkeys, and that's not the problem. The same behaviour occurs.

I will describe exactly what happens.

I start the script. The message box pops up. Yay, all good so far.

I close the message box. Windows runs as per usual.

I press F11, the screen goes blank.

About a second later, the screen turns back on.

I press a key, the screen goes blank, and about a second later, it turns back on.

I move the mouse, the screen goes blank, and about a second later, it turns back on.

If I continually move the mouse, the screen goes black, but flickers every second or so, as if it's trying to turn on but is turned off again immediately.

If I press F10, the screen turns on or stays on.

If I press esc, the script exits.

I think this must be a hardware issue of some sort. But I can't see what's causing it.

Share this post


Link to post
Share on other sites

I can confirm mdixon's results on my (Toshiba) laptop with XP sp3, and AutoIt 3.2.10/Beta 3.2.11.5

Slightly different twist though, if I hit F11 before I click OK on the instruction msgbox, my screen will stay blank until I move the mouse or touch a key. Then it starts the whole "on-off" routine.

Interestingly, if I hit F11 before I dismiss the msgbox and i dismiss the msgbox by hitting ENTER rather than clicking OK with the mouse, the screen goes off, comes back on and then will go on-off as I hit keys or move the mouse.

Share this post


Link to post
Share on other sites

Same on my Laptop (Vista).

Btw, is it possible to turn off only one monitor if you use dual view (e.g. laptop monitor and connected external monitor)? :D


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

On my system some software turn on the monitor though not press buttons or move the mouse.

Is there a way to check the check the status of the monitor if it is turned off or or?

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

Hi everybody

How can I Modify this script in order to "Monitor_ON" if Mouse Moves when my monitor is in "Monitor_OFF"

Thanks for responding

Potit Panda

Edited by potitpanda

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

I start the script , after few seconds maybe 10 or so the screen is turned on & then off again & if flickers like this constantly.

It must be the mouse that is turning the monitor off, cuz after I turned off my mouse screen stayed turned off. But if I move my mouse purposely, the screen is not turned on. This is weird.

Well ether way this code is a real life saver. will just have to figure out how keep the screen turned off until i hit the hotkey.

EDIT: I dont know why, but it works fine now.

An idea, what you can do with this script:

there was this project where ppl tried to force the user to go away from the computer for 5 min every hour or so. but since ppl were to smart for their own good+limitations of autoitscropt, nothing came out of it. Now think: you kill the screen & no mater what you press it will stay blank for 5 min. & you cant do anything about it. so its a perfect solution.!

Edited by goldenix

My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

@MrCreatoR

Ive little modified your function because it wasnt easy to handle with some scripts...

btw, ive deleted _IdleWaitCommit function because it works fine without :)

Function _Monitor

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

Func _Monitor($run = 1)
    Local $Progman_hwnd = WinGetHandle('[CLASS:Progman]')

    If $run = 0 Then
        BlockInput(1)
        DllCall('user32.dll', 'int', 'SendMessage', _
                'hwnd', $Progman_hwnd, _
                'int', $lciWM_SYSCommand, _
                'int', $lciSC_MonitorPower, _
                'int', $lciPower_Off)
        Return 1
    ElseIf $run = 1 Then
        BlockInput(0)
        DllCall('user32.dll', 'int', 'SendMessage', _
                'hwnd', $Progman_hwnd, _
                'int', $lciWM_SYSCommand, _
                'int', $lciSC_MonitorPower, _
                'int', $lciPower_On)
        Return 1
    EndIf
    Return 0
EndFunc   ;==>_MonitoroÝ÷ ØLZ^jëh×6_Monitor(0) ;Turn off monitor
Sleep(10000) ;Wait 10 seconds
_Monitor(1) ;Turn on monitor

Edit : Hum..._IdleWaitCommit is for mouse movement... but I dont think I have to add it :o

Edit 2 : Added BlockInput

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

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