現在我的顯示器被設置爲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());
}
}
}
}
在文本文件我」正在寫,結果看到的變化所有的結果都是一樣的:
通用即插即用監視器 DesktopMonitor1 通用即插即用監視器
每一秒鐘我看到:
通用即插即用監視器 DesktopMonitor1 通用即插即用監視器
當我在監視器源切換到HDMI 1