有哪位大神研究过软关闭显示器的?
通过以下代码可以成功关闭显示器,但前提是不要动键盘和鼠标,一动就会恢复显示,我想的是能不能不受键盘和鼠标的干扰,黑屏后就一直黑屏。于是我想到了循环关闭,不断地尝试关闭动作,问题来了,显示器会闪白屏,这就有点三寨了,不知有哪位同仁遇到这问题并得到解决的?
当然,如果能禁止键盘、鼠标自动恢复显示器的也行,但最好保留软键盘,模拟鼠标正常工作,以不影响挂机任务。$user32 = DllOpen("user32.dll")
$begin = TimerInit()
While 1
_MonitorOff()
If TimerDiff($begin) >= 10000 Then ExitLoop
WEnd
_MonitorON()
Func _MonitorOff()
$Desktophwnd = WinGetHandle("")
DllCall($user32, "int", "SendMessage", "hwnd", $Desktophwnd, "int", 274, "int", 61808, "int", 2)
EndFunc
Func _MonitorON()
$Desktophwnd = WinGetHandle("")
DllCall($user32, "int", "SendMessage", "hwnd", $Desktophwnd, "int", 274, "int", 61808, "int", -1)
EndFunc #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('')
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('')
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 高端,学习了,感谢分享! 蛋神果然不一般~ 回复 2# netegg
谢谢蛋神,前段时间出差,没空来逛,请见谅。您发的这篇文章我也看过,在ThinkPad笔记本上测试,依然会闪白屏。感觉该笔记本一唤醒显示器就立即亮,所以就算循环关闭显示器,也会闪白屏
唯一的办法就是想能不能hook系统开启显示器的命令,终止亮屏,这样不知道能不能实现。 hook硬件比较麻烦了,没试过,也许可以,不过软关闭显示器有点难度 有点可怕的代码和想法,假如恶意使用,会导致无辜的系统黑屏。 回复 7# tvzml
不要往恶意的方面想啊,这是有需求,才会提这样的要求,对吧?
页:
[1]