AuScripter Posted January 11, 2019 Share Posted January 11, 2019 Hi, I'm trying to create a script that runs in the background while turning off the monitor. Unfortunately, the script execution stops when the monitor is off. I wish, however, that the script will continue. This is an example of my implementation: expandcollapse popup#include <File.au3> Global Const $lciWM_SYSCommand = 274 Global Const $lciSC_MonitorPower = 61808 Global Const $lciPower_Off = 2 Global Const $lciPower_On = -1 Global $LogFileName = @ScriptDir & "\MonitorOffTest.log" HotKeySet("^q", "QuitScript") WriteLog("Start script") Sleep(5000) _Monitor(0) WriteLog("Monitor off") $Run = True While $Run WriteLog("Main loop") Sleep(5000) WEnd Func WriteLog($logtext) Local $hFile = FileOpen($LogFileName, 1) _FileWriteLog($hFile, $logtext) FileClose($hFile) EndFunc 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 Func QuitScript() WriteLog("Quit script") $Run = False EndFunc It creates log entries as follows: 2019-01-11 14:00:58 : Start script 2019-01-11 14:01:03 : Monitor off 2019-01-11 14:01:03 : Main loop 2019-01-11 14:06:24 : Main loop 2019-01-11 14:06:29 : Main loop 2019-01-11 14:06:32 : Quit script As you can see, nothing is logged when the monitor is off. After moving the mouse, it is running again. Who has a hint for me how to make sure that the monitor is off, but the script and all other processes on the computer are still running? Btw: The computer I'm testing with is a Surface 3 Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted January 11, 2019 Moderators Share Posted January 11, 2019 Obvious question, why do you need to turn the monitor off in order to run your script? ===In case you missed it, this is a Mod stepping into a thread=== "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
AuScripter Posted January 11, 2019 Author Share Posted January 11, 2019 The idea is to turn the monitor off when the script is idle (main loop). The plan is to activate the monitor only during the activities. Unfortunately, the script stops and misses the time of the next activity. Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted January 11, 2019 Moderators Share Posted January 11, 2019 Thank you for the clarification. The thread is fine to continue. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
Danp2 Posted January 11, 2019 Share Posted January 11, 2019 Have you tried commenting out the Sleep command? Perhaps there is an incompatibility with the way it is implemented and your monitor off functionality. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
AuScripter Posted January 11, 2019 Author Share Posted January 11, 2019 Which Sleep command do you mean? The one within the main loop? No, I didn't try this. Would not that result in too much load on the System? Link to comment Share on other sites More sharing options...
Danp2 Posted January 11, 2019 Share Posted January 11, 2019 Yes, the one inside the main loop. Don't worry about system load at this point. The idea is to identify the reason the script is pausing. If it turns out to be the Sleep command, you would need to replace it with something else. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
AuScripter Posted January 11, 2019 Author Share Posted January 11, 2019 Strange! The script seems to continue without Sleep. I would not have gotten that idea at all. But what can I use as an alternative? The original script does a lot more in the main loop and Sleep is used in different places. Link to comment Share on other sites More sharing options...
Danp2 Posted January 11, 2019 Share Posted January 11, 2019 You could try calling the Windows API directly -- Func _Sleep($iDelay) DllCall("Kernel32.dll", "none", "Sleep", "dword", $iDelay) EndFunc Code found here. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
AuScripter Posted January 11, 2019 Author Share Posted January 11, 2019 Tried it. The same result: 2019-01-11 15:51:57 : Start script 2019-01-11 15:52:02 : Monitor off 2019-01-11 15:52:02 : Main loop 2019-01-11 15:52:07 : Main loop2019-01-11 15:52:12 : Main loop2019-01-11 15:55:33 : Main loop 2019-01-11 15:55:38 : Main loop 2019-01-11 15:55:43 : Main loop 2019-01-11 15:55:48 : Main loop 2019-01-11 15:55:53 : Main loop 2019-01-11 15:55:58 : Main loop 2019-01-11 15:56:03 : Main loop 2019-01-11 15:56:08 : Quit script The loop stops after three passes (red) and will not resume until the computer is re-activated with the mouse (green). Link to comment Share on other sites More sharing options...
Danp2 Posted January 11, 2019 Share Posted January 11, 2019 What are your power management settings? Is it possible that the computer is entering a "suspended" state after you send the command to shut off the monitor? Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
AuScripter Posted January 11, 2019 Author Share Posted January 11, 2019 No. For mains operation all options are set to "Never" Link to comment Share on other sites More sharing options...
AuScripter Posted January 11, 2019 Author Share Posted January 11, 2019 An alternative idea: Maybe I could also set the screen brightness to 0. Is that possible with Autoit? With Windows on-board means this does not work with the surface under Windows 10. Minimum brightness setting here is 25%. Link to comment Share on other sites More sharing options...
AuScripter Posted January 11, 2019 Author Share Posted January 11, 2019 In the meantime, I have read that it is probably a phenomenon of Windows tablets. So I searched in the wrong place. Not AutoIT is the problem, but the hardware. Link to comment Share on other sites More sharing options...
Earthshine Posted January 12, 2019 Share Posted January 12, 2019 There may be a setting in windows to allow applications to run in the background when they don’t have focus My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
seadoggie01 Posted April 22, 2019 Share Posted April 22, 2019 @AuScripter The best I found was using GDI+ to create a black overlay to hide that my screen was on. I used this as a template. Both Windows 7 and 10 seem to do this 😕 (FYI: I'm downloading invoices at work and my monitor heats up and does the old TV thing of "staining" pixels for a short while.) All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types 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