现在我的显示器设置为DVI-D,我知道这是我的电脑。但是,例如,我的PlayStation4连接到HDMI1,我想做的是当我将监视器信号源改为HDMI1时检测它,当我将其改为DVI时检测它,这样我就可以知道我的监视器信号源是在pc上还是在ps4上。
到目前为止,我尝试的是这样的。我在我的设计器中添加了一个计时器,我运行了40秒,并在计时器中调用了一个方法:
int counttimer2 = 0;
private void timer2_Tick(object sender, EventArgs e)
{
if (counttimer2 == 40)
{
w.Close();
timer2.Stop();
}
DetectScreenName();
counttimer2 += 1;
}和DetectScreenName方法:
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时,它没有改变
发布于 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中所解释的那样。
https://stackoverflow.com/questions/33684373
复制相似问题