在 .NET 中检测 HDMI 电缆事件? [英] Detecting HDMI cable event within .NET?

查看:21
本文介绍了在 .NET 中检测 HDMI 电缆事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当 HDMI 电缆从 .NET 框架内插入笔记本电脑的 HDMI 端口时,我正在尝试检测该事件.我知道触发了一个事件,因为当插入电缆时,Windows 会发出明显的新硬件"声音并将屏幕分辨率更改为更合适的分辨率.

I'm trying to detect the event when a HDMI cable is plugged into the HDMI port of my laptop from within the .NET framework. I know that there is an event being triggered, because when the cable is plugged in, Windows makes the obvious "new hardware" sound and changes screen resolution to something more suitable.

我有点厌倦了手动将音频设备更改为 HDMI 输出,所以想编写一个小应用程序来为我做这件事.

I'm getting a bit tired of having the change my audio device to HDMI output by hand so want to write a small app to do it for me.

推荐答案

我很惊讶这里没有人提到 DisplaySettingsChanging 或 DisplaySettingsChanged 事件.当您插入或拔出 HDMI 电缆时,o/s 会为您检测并重新枚举屏幕.你可以捕捉到这些事件.

I'm very surprised that noone here mentioned about the DisplaySettingsChanging or DisplaySettingsChanged events. When you plug-in or out an HDMI cable, o/s detects it for you and renumerates the screens. You can catch that events.

一段示例代码是:

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)        
        {

            Microsoft.Win32.SystemEvents.DisplaySettingsChanged += SystemEvents_DisplaySettingsChanged;

            Microsoft.Win32.SystemEvents.DisplaySettingsChanging += SystemEvents_DisplaySettingsChanging;

            Console.Read();
        }

        static void SystemEvents_DisplaySettingsChanged(object sender, EventArgs e)
        {
            Console.WriteLine("Display settings have been changed.");
        }

        static void SystemEvents_DisplaySettingsChanging(object sender, EventArgs e)
        {
            Console.WriteLine("Display settings are changing now...");
        }

    }
}

这篇关于在 .NET 中检测 HDMI 电缆事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆