找回密码
 加入
搜索
查看: 5683|回复: 7

[AU3基础] 有哪位大神研究过软关闭显示器的?

  [复制链接]
发表于 2014-10-15 20:12:27 | 显示全部楼层 |阅读模式
通过以下代码可以成功关闭显示器,但前提是不要动键盘和鼠标,一动就会恢复显示,我想的是能不能不受键盘和鼠标的干扰,黑屏后就一直黑屏。
于是我想到了循环关闭,不断地尝试关闭动作,问题来了,显示器会闪白屏,这就有点三寨了,不知有哪位同仁遇到这问题并得到解决的?
当然,如果能禁止键盘、鼠标自动恢复显示器的也行,但最好保留软键盘,模拟鼠标正常工作,以不影响挂机任务。
$user32 = DllOpen("user32.dll")

$begin = TimerInit()
While 1
        _MonitorOff()
        If TimerDiff($begin) >= 10000 Then ExitLoop
WEnd
_MonitorON()


Func _MonitorOff()
        $Desktophwnd = WinGetHandle("[CLASS:Progman]")
        DllCall($user32, "int", "SendMessage", "hwnd", $Desktophwnd, "int", 274, "int", 61808, "int", 2)
EndFunc

Func _MonitorON()
        $Desktophwnd = WinGetHandle("[CLASS:Progman]")
        DllCall($user32, "int", "SendMessage", "hwnd", $Desktophwnd, "int", 274, "int", 61808, "int", -1)
EndFunc
发表于 2014-10-26 13:15:54 | 显示全部楼层
[au3]#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[/au3]

评分

参与人数 1金钱 +30 收起 理由
txm888 + 30 谢谢帮忙

查看全部评分

发表于 2014-10-28 16:31:31 | 显示全部楼层
高端,学习了,感谢分享!
发表于 2014-10-29 09:55:51 | 显示全部楼层
蛋神果然不一般~
 楼主| 发表于 2014-11-7 09:48:16 | 显示全部楼层
回复 2# netegg

谢谢蛋神,前段时间出差,没空来逛,请见谅。您发的这篇文章我也看过,在ThinkPad笔记本上测试,依然会闪白屏。感觉该笔记本一唤醒显示器就立即亮,所以就算循环关闭显示器,也会闪白屏
唯一的办法就是想能不能hook系统开启显示器的命令,终止亮屏,这样不知道能不能实现。
发表于 2014-11-7 10:00:00 | 显示全部楼层
hook硬件比较麻烦了,没试过,也许可以,不过软关闭显示器有点难度
发表于 2014-11-7 22:49:42 | 显示全部楼层
有点可怕的代码和想法,假如恶意使用,会导致无辜的系统黑屏。
 楼主| 发表于 2014-11-9 21:52:54 | 显示全部楼层
回复 7# tvzml


    不要往恶意的方面想啊,这是有需求,才会提这样的要求,对吧?
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-4 15:51 , Processed in 0.077496 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表