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:
#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