首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我怎样才能检测到我的显示器现在设置为什么信号源?

我怎样才能检测到我的显示器现在设置为什么信号源?
EN

Stack Overflow用户
提问于 2015-11-13 09:15:26
回答 1查看 136关注 0票数 2

现在我的显示器设置为DVI-D,我知道这是我的电脑。但是,例如,我的PlayStation4连接到HDMI1,我想做的是当我将监视器信号源改为HDMI1时检测它,当我将其改为DVI时检测它,这样我就可以知道我的监视器信号源是在pc上还是在ps4上。

到目前为止,我尝试的是这样的。我在我的设计器中添加了一个计时器,我运行了40秒,并在计时器中调用了一个方法:

代码语言:javascript
复制
int counttimer2 = 0;
    private void timer2_Tick(object sender, EventArgs e)
    {
        if (counttimer2 == 40)
        {
            w.Close();
            timer2.Stop();
        }
        DetectScreenName();
        counttimer2 += 1;
    }

和DetectScreenName方法:

代码语言:javascript
复制
private void DetectScreenName()
        {
            if (counttimer2 < 40)
            {
                SelectQuery q = new SelectQuery("SELECT Name, DeviceID, Description FROM Win32_DesktopMonitor");
                using (ManagementObjectSearcher mos = new ManagementObjectSearcher(q))
                {
                    foreach (ManagementObject mo in mos.Get())
                    {
                        Console.WriteLine("{0}, {1}, {2}",
                            mo.Properties["Name"].Value.ToString(),
                            mo.Properties["DeviceID"].Value.ToString(),
                            mo.Properties["Description"].Value.ToString());
                        results.Add(mo.Properties["Name"].Value.ToString());
                        results.Add(mo.Properties["DeviceID"].Value.ToString());
                        results.Add(mo.Properties["Description"].Value.ToString());
                        w.WriteLine(mo.Properties["Name"].Value.ToString());
                        w.WriteLine(mo.Properties["DeviceID"].Value.ToString());
                        w.WriteLine(mo.Properties["Description"].Value.ToString());
                    }
                }
            }
        }

在文本文件上,我正在编写结果以查看更改,所有结果都是相同的:

通用PnP监视器DesktopMonitor1通用PnP监视器

我看到的每一秒:

通用PnP监视器DesktopMonitor1通用PnP监视器

当我将监视器信号源切换到HDMI 1时,它没有改变

EN

回答 1

Stack Overflow用户

发布于 2015-12-04 07:46:43

当您切换监视器的信号源时,您的计算机没有任何变化-就像关闭了监视器一样。

不幸的是,您不能可靠地检测到这一点,正如Is there any way to detect the monitor state in Windows (on or off)?Detect external display being connected or removed under Windows 7中所解释的那样。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33684373

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档