【发布时间】:2016-02-14 12:58:30
【问题描述】:
现在我的显示器设置为 DVI-D,我知道这是我的电脑。 但例如我的 playstation 4 连接到 HDMI 1 我想要做的是当我将显示器源更改为 HDMI 1 时检测它,当我将其更改回 DVI-D 时检测它,这样我就可以知道我的显示器源何时在 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 监视器 桌面监视器1 通用 PnP 监视器
我看到的每一秒:
通用 PnP 监视器 桌面监视器1 通用 PnP 监视器
当我将监视器源切换到 HDMI 1 时它没有改变
【问题讨论】: