在python中监视显示状态? [英] Monitoring a displays state in python?

查看:27
本文介绍了在python中监视显示状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何判断 Windows 何时更改显示器电源状态?

How can I tell when Windows is changing a monitors power state?

推荐答案

看来,当 Windows 要启动屏幕保护程序或关闭显示器时,它会发送一个 WM_SYSCOMMAND 到最顶层带有 SC_SCREENSAVEwParam(启动屏幕保护程序)或 SC_MONITORPOWERwParam 的窗口>lParam 为 1 或 2(关闭显示器).此消息随后将传递给 DefWindowProc,后者将实际执行操作.因此,如果您的窗口恰好是最顶层的窗口,您可以拦截这些事件并忽略它们(或者在将它们传递给 DefWindowProc 之前做任何其他您想做的事情).

It seems that, when Windows wants to start the screen saver or turn the monitor off, it will send a WM_SYSCOMMAND to the topmost window with a wParam of SC_SCREENSAVE (to start the screen saver) or a wParam of SC_MONITORPOWER and a lParam of 1 or 2 (to turn the monitor off). This message will then be passed to DefWindowProc, which will actually do the action. So, if your window happens to be the topmost one, you can intercept these events and ignore them (or do anything else you want before passing them to DefWindowProc).

在 Windows Vista 上,似乎有一种更直观、更可靠的方式来了解显示器电源状态.您调用 RegisterPowerSettingNotification 以告诉系统向您的窗口发送一个 WM_POWERBROADCAST 消息,其中包含 PBT_POWERSETTINGCHANGEwParamlParam 指向 POWERBROADCAST_SETTING 结构.

On Windows Vista, there seems to be a more intuitive, and more reliable, way to know the monitor power state. You call RegisterPowerSettingNotification to tell the system to send your window a WM_POWERBROADCAST message with a wParam of PBT_POWERSETTINGCHANGE and a lParam pointing to a POWERBROADCAST_SETTING structure.

我无法测试其中任何一个,因为我目前附近没有任何装有 Windows 的计算机.但是,我希望它们为您指明了正确的方向.

I cannot test either of them since I currently do not have any computer with Windows nearby. I hope, however, they point you in the right direction.

参考文献:

这篇关于在python中监视显示状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆