切换Windows的监视器/电视显示模式



我有两台戴尔显示器和一台电视。我经常用电视看电影。我想创建一个脚本,这样我的辅助屏幕就可以从辅助戴尔显示器切换到电视,而不会影响我的主显示器。

我知道这可以通过各种方式实现,但我想创建一个脚本,使它能够检测当前的活动屏幕,然后切换到另一个,这样我的妻子可以只需双击它在两者之间切换。

有人可以帮助我开始让我知道我可以使用哪种脚本语言和哪些库/dll我将需要使用?

对于任何好奇的人来说,我最终为此创建了一个c#控制台应用程序。这样我就可以使用winapi来确定我所处的显示模式并切换到我想要的模式。它不会被设置成每个人都想要的样子,但它应该是一个很好的起点。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DisplaySwitcher
{
    class Program
    {
        [System.Runtime.InteropServices.DllImport("user32.dll")]
        public static extern int GetSystemMetrics(int nIndex);
        public const int SM_CMONITORS = 80;
        static void Main(string[] args)
        {
            int iNumberOfDisplays = GetSystemMetrics(SM_CMONITORS);
            string displaySwitch = null;
            switch (iNumberOfDisplays)
            {
                case 1: // TV mode (only detects 1 display)
                    displaySwitch += "/external";
                    break;
                case 2: // Normal mode (extended display)
                    displaySwitch += "/clone";
                    break;
                default:
                    MessageBox.Show("Unknown display mode detected");
                    break;
            }
            executeCommand(displaySwitch);
        }
        private static void executeCommand(string displaySwitch)
        {
            System.Diagnostics.Process process = new System.Diagnostics.Process();
            System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
            startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            startInfo.FileName = "DisplaySwitch.exe";
            startInfo.Arguments = displaySwitch;
            process.StartInfo = startInfo;
            process.Start();
        }
    }
}

最新更新