栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用Windows发送DDC / CI命令以在Windows上进行监视?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用Windows发送DDC / CI命令以在Windows上进行监视?

使用Windows Monitor API可以轻松实现。我不认为那里没有任何Python绑定,并且pywin32不包含那些函数。但是,使用

ctypes
它们并不难。

这是一个将显示器切换至软关机然后再打开的示例。使其适应更改输入源等应该非常容易。毕竟,唯一复杂的部分是获取物理监视器的句柄:

from ctypes import windll, byref, Structure, WinError, POINTER, WINFUNCTYPEfrom ctypes.wintypes import BOOL, HMONITOR, HDC, RECT, LPARAM, DWORD, BYTE, WCHAR, HANDLE_MonITORENUMPROC = WINFUNCTYPE(BOOL, HMONITOR, HDC, POINTER(RECT), LPARAM)class _PHYSICAL_MonITOR(Structure):    _fields_ = [('handle', HANDLE),     ('description', WCHAR * 128)]def _iter_physical_monitors(close_handles=True):    """Iterates physical monitors.    The handles are closed automatically whenever the iterator is advanced.    This means that the iterator should always be fully exhausted!    If you want to keep handles e.g. because you need to store all of them and    use them later, set `close_handles` to False and close them manually."""    def callback(hmonitor, hdc, lprect, lparam):        monitors.append(HMonITOR(hmonitor))        return True    monitors = []    if not windll.user32.EnumDisplayMonitors(None, None, _MonITORENUMPROC(callback), None):        raise WinError('EnumDisplayMonitors failed')    for monitor in monitors:        # Get physical monitor count        count = DWORd()        if not windll.dxva2.GetNumberOfPhysicalMonitorsFromHMONITOR(monitor, byref(count)): raise WinError()        # Get physical monitor handles        physical_array = (_PHYSICAL_MonITOR * count.value)()        if not windll.dxva2.GetPhysicalMonitorsFromHMONITOR(monitor, count.value, physical_array): raise WinError()        for physical in physical_array: yield physical.handle if close_handles:     if not windll.dxva2.DestroyPhysicalMonitor(physical.handle):         raise WinError()def set_vcp_feature(monitor, pre, value):    """Sends a DDC command to the specified monitor.    See this link for a list of commands:    ftp://ftp.cis.nctu.edu.tw/pub/csie/Software/X11/private/VeSaSpEcS/VESA_document_Center_Monitor_Interface/mccsV3.pdf    """    if not windll.dxva2.SetVCPFeature(HANDLE(monitor), BYTE(pre), DWORd(value)):        raise WinError()# Switch to SOFT-OFF, wait for the user to press return and then back to onfor handle in _iter_physical_monitors():    set_vcp_feature(handle, 0xd6, 0x04)    raw_input()    set_vcp_feature(handle, 0xd6, 0x01)


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/596590.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号