Golbez Posted February 25, 2010 Share Posted February 25, 2010 (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 make a new function then call this: Global $io_control = "off" Func Monitor($io_control = "on") Opt("WinTitleMatchMode", 4) 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 i found it off this: http://www.autoitscript.com/forum/index....owtopic=87625&st=0&p=629136&#entry629136 Edited February 25, 2010 by Golbez Link to comment Share on other sites More sharing options...
jamesstp20 Posted October 4, 2011 Share Posted October 4, 2011 Thanks but is there any way to turn screen off after the mouse is not moving for exemple 2 minutes and turning the screen on by moving the mouse ? Link to comment Share on other sites More sharing options...
D00M4N Posted June 14, 2013 Share Posted June 14, 2013 great , thx for your job Link to comment Share on other sites More sharing options...
tonycst Posted August 31, 2013 Share Posted August 31, 2013 (edited) Update December 4 2013 V1.1 Fixed inability to open settings second time. Added 500 milisecons delay for monitor off to compensate for mouse moviment. Parented some pop up messages. Replaced tray menu with custom Exit and About items. Fixed blank values for coordinates. Not saved unless you click Save, but will always show 0 if nothing else was previously set. I made one for my laptop touchscreen using this example. Works lovely. It has options to change things so give it a try. You can select what ever buttons to display. Monitor off,Restart or ShutDown. Set visibility of buttons. Enable Start with Windows. Hope anybody likes this. Source files Source.zip Executable Laptop Monitor OFF.zip Screenshot Edited September 5, 2013 by tonycst Link to comment Share on other sites More sharing options...
Schyzo Posted April 24, 2015 Share Posted April 24, 2015 Hi MrCreatoR, first let me say I love your original script, it does wonders for me. I'm trying to push it a little bit further and I'm running into a wall... My goal is to have an automated script to open and close the monitor at set times. ie open at 7:00AM and close at 22:00. It's for info screens in a bank and we want to shut them down at night so they'll last longer. So far, my script is built around yours, and it does the OFF part perfectly but the ON part doesn't work automatically. Weirdly enough, If I hit F10 manually it comes up fine. Would you have any idea where I erred on the ON part ? Any helpfull comments will be appreciated ! expandcollapse popup; AutoIt Screen Control ; Created: 2015/04/15 - Schyzo #include <AVIConstants.au3> #include <WinAPISys.au3> #include <GuiConstantsEx.au3> #include <TreeViewConstants.au3> #include <MsgBoxConstants.au3> #include <Date.au3> #include <Debug.au3> HotKeySet("{F11}", "_Monitor_OFF") HotKeySet("{F10}", "_Monitor_ON") HotKeySet("{F9}", "_Quit") Global $iStart, $iExit, $iHour, $iMin, $iSec, $TimeOff, $gTimeOffHour, $TimeOn, $TimeOff, $TimeOffHour, $gTimeOffMin, $TimeOffMin, $TimeOff, $gTimeOnHour, $TimeOnHour, $gTimeOnMin, $TimeOnMin, $TimeOnMin, $gLoopTime, $LoopTime ; GUI GUICreate("Screen Control", 250, 250) ; Stop time GUICtrlCreateLabel("Heure d'arrêt du moniteur (24h)", 10, 20, 300, 20) $gTimeOffHour = GUICtrlCreateInput("22", 10, 40, 40, 20) $gTimeOffMin = GUICtrlCreateInput("00", 60, 40, 40, 20) ; Start time GUICtrlCreateLabel("Heure de départ du moniteur (24h)", 10, 70, 300, 20) $gTimeOnHour = GUICtrlCreateInput("08", 10, 90, 40, 20) $gTimeOnMin = GUICtrlCreateInput("40", 60, 90, 40, 20) GUICtrlCreateLabel("Temps de pause (secondes)", 10, 120, 300, 20) $gLoopTime = GUICtrlCreateInput("5", 10, 140, 40, 20) ; Ok BUTTON $iStart = GUICtrlCreateButton("Start", 10, 180, 100, 30) $iExit = GUICtrlCreateButton("Exit", 130, 180, 100, 30) ; GUI MESSAGE LOOP GUISetState(@SW_SHOW) Sleep(5000) ControlClick("Screen Control", "", "Start") ; Auto start process after 5 secs While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $iStart ;MsgBox($MB_SYSTEMMODAL, "", "Start clicked.") ;Global $TimeOff = _TimeToTicks($TimeOffHour, $TimeOffMin, 0) $TimeOffHour = GUICtrlRead($gTimeOffHour) ; return time OFF hour $TimeOffMin = GUICtrlRead($gTimeOffMin) ; return time OFF min $TimeOnHour = GUICtrlRead($gTimeOnHour) ; return time ON hour $TimeOnMin = GUICtrlRead($gTimeOnMin) ; return time ON min $LoopTime = GUICtrlRead($gLoopTime) ; return Loop Time $LoopTime = $LoopTime * 1000 GUISetState(@SW_HIDE) _IniTime() _StartScreen() Case $iExit ;MsgBox($MB_SYSTEMMODAL, "", "Exit clicked.") Exit EndSwitch WEnd ; *** Start Process *** Func _StartScreen() #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("{F9}", "_Quit") MsgBox(64, "Monitor On/Off", "Press F11 to turn off the monitor." & @LF & _ "Press F10 to turn on the monitor back." & @LF & _ "Press F9 to turn on the monitor and exit program.", 2) While 1 _CheckTime() ; Go check current time vs ON and OFF time WEnd EndFunc ;==>_StartScreen ; *** Lecture de l'heure de départ et d'arrêt *** Func _IniTime() ; calculate with time $TimeOff = _TimeToTicks($TimeOffHour, $TimeOffMin, 0) $TimeOn = _TimeToTicks($TimeOnHour, $TimeOnMin, 0) EndFunc ;==>_IniTime ; *** vérification de l'heure courante et ouvrir et fermer l'écran au besoin *** Func _CheckTime() Local $iStartTicks = _TimeToTicks(@HOUR, @MIN, @SEC) ;MsgBox($MB_SYSTEMMODAL, "StartTicks", $iStartTicks,2) Local $sMsg = "" Switch $iStartTicks Case 0 To $TimeOn ;$sMsg = "0 to ON = OFF" _Monitor_OFF() Sleep($LoopTime) Case $TimeOn To $TimeOff ;$sMsg = $MonitorIsOff & "ON to OFF = ON " _Monitor_ON() Sleep($LoopTime) Case $TimeOff To 86340000 ; TimeOFF to 23:59:00 in ticks ;$sMsg = "OFF to 24 - OFF" _Monitor_OFF() Sleep($LoopTime) Case Else $sMsg = "What are you still doing up?" EndSwitch ;MsgBox($MB_SYSTEMMODAL, "", $sMsg, 2) EndFunc ;==>_CheckTime 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 ;==>_Monitor_ON 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 ;==>_Monitor_OFF 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 ;==>_IdleWaitCommit Func _Quit() _Monitor_ON() Exit EndFunc ;==>_Quit Link to comment Share on other sites More sharing options...
pozhidaevak Posted July 28, 2015 Share Posted July 28, 2015 Hello!Enabling and disabling of a monitor works great. But I also need to know current status (enabled or disabled) of a monitor.Please explain me how to determine current state of a monitor? Link to comment Share on other sites More sharing options...
Mxstern18 Posted March 6, 2017 Share Posted March 6, 2017 On 4/9/2008 at 6:21 AM, mdixon said: 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. Try changing the Sleep to a smaller number-- Also I added VOLUME MUTE, and changed my hotkeys. MaxOFF.au3 Link to comment Share on other sites More sharing options...
Guest Posted March 9, 2017 Share Posted March 9, 2017 I hope it will work on my windows 8 tablet. Thanks! Link to comment Share on other sites More sharing options...
FreeLancA Posted August 23, 2017 Share Posted August 23, 2017 Hi guys, sorry to necro this thread. But I'm in need for one of the codes on page one to work for me. The monitor off for three seconds and on again. Two or even one second preferred. I tried copying the code, but I get the following (attached) error when running. I have a pc at work that will display a static image all day (jobs list for the team) and wish for the screen to 'power cycle' every hour so so to avoid damage. is the code just out of date for win 10? Thanks in advance for your assistance, Brett. Link to comment Share on other sites More sharing options...
SharkyEXE Posted March 18, 2021 Share Posted March 18, 2021 (edited) Hello If posssible. I need help I have 1) run the script 2) the monitor went off 3) push the mouse or press the buttons on the mouse-the monitor does NOT turn on 4) if you press any button on the keyboard-the monitor turned on + the mouse became working - both on moving the mouse, and on the mouse you press the buttons 5) if the script does not finish in the tray, if you do not click the Exit button on the script or Finish the script in the tray, the script starts working again after 1 minute Thank You! Edited March 18, 2021 by SharkyEXE Link to comment Share on other sites More sharing options...
Yedidya Posted May 17, 2023 Share Posted May 17, 2023 Is there any way to make this work for only one monitor if I have multiple monitors? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now