Expected Reading Time: 9 minutes

Some of you will feel the pain of having a setup consisting of multiple monitors and then, for example, a TV on which you play a few games every now and then. You don't need your 2 main monitors and want to have only the TV active as an output source instead. For this you have to plow through the Windows menus and then turn off one monitor, turn on the TV, then select the main display and and...

It doesn't even necessarily have to be the gaming setup, but can perhaps involve a dedicated setup for work where you have to adjust your monitor/audio settings more often and do the same thing over and over again.

This was so annoying that I was looking for a solution. I found the perfect solution for me to control the whole procedure including an audio device change via hotkey. That means you can use a hotkey on your keyboard or a button on an Elgato Streamdeck if you have one.

Thus, the solution is a kind of partial automation, since it is very difficult to fully automate when you want to play and always switch to the respective setup. Although that would certainly be possible. But it seems rather pointless to me in the vast majority of cases.

Why should I switch between different configurations with multiple monitors?

A common problem when using multiple screens, especially if some of them are duplicated, is that NVIDIA drivers enable vertical synchronization (to prevent image tearing) only for the main screen, and only if that screen is not duplicated. This is not a problem in everyday desktop use, but when it comes to gaming or HD movies, there is no way to prevent image tearing on a screen other than the main screen if it is duplicated. If you have a TV connected in addition, the situation becomes inconvenient, since every time you want to play a game or watch a movie on the TV, you have to make it the primary screen. Oh, and of course the whole thing works not only for NVIDIA, but also AMD or even Intel.

With the script you can now easily create different configuration profiles for your screens, such as "TV only", "Screen only", "TV and screen duplicated" or "Screen 1 and 2 duplicated", and quickly switch between them. Furthermore, you can use complementary tools and make other settings when pressing a button.

So we will also change the audio device here, because you would then want to use your headphones when gaming, for example, and no longer your speakers. This would also work for the microphone. Graphics card settings could also be adjusted if desired.

Requirements

We need some tools first:

Don't be surprised, the tools and their websites are older but work fine on modern Windows systems like Windows 10 or Windows 11 (both tested).

You can install AutoHotkey normally with the installer via the exe file. The tool will then be placed below the programs on your primary hard drive.

After the download then nircmd-x64.zip simply unpack and use the nircmd64.exe right-click to start as admin and let the installer create the file in Windows. The file is then located directly under the Windows path: C:\Windows\nircmd.exe

The MonitorProfileSwitcher.zip must also be unpacked again. The folder that results from this should then, if it is different, be renamed to MonitorProfileSwitcher must be renamed. You must then rename this folder under C:\Program Files\ so that the path at the end of the file is C:\Program Files\MonitorProfileSwitcher reads. In German the folder is simply called Programs instead of Program Files.

This creates all the necessary conditions to now create the script and create any hotkeys.

MonitorProfileSwitcher Create profiles

To create profiles, for the sake of simplicity, you should use the MonitorSwitcherGUI.exe at C:\Program Files\MonitorProfileSwitcher Open path. A small black monitor icon opens at the bottom right of the mini icons in the taskbar, where the speaker and time are also located. You can click on it with the left mouse button and a small window will open above the icon.

There you can now go through Save profiles and Delete Profile Create and delete profiles. The configuration that is currently active is always saved. That is, if you want to have only your TV active from three connected monitors and this also as the main monitor, you must have this setup currently active and from your TV Save profiles click and then on New Profile. Here it is important to note: The profiles must not contain spaces in the name! Ideally, work with hyphens.

You don't need to store the hotkeys here, because they only work when the GUI tool is running and we don't want to use it permanently, because we solve it via the command line tool and use AutoHotkey.

Scripting

Creates a new file with the .ahk ending so for example Audio & Monitor Device Switcher.ahk. You must have the file extensions enabled to be able to create the file including the extension. If you don't know how to do that, you can read about it in an article from GIGA to Windows 10 and 11: Show file extensions read up.

You can now place the file wherever you want. In the course of this you should create a shortcut of this file. You do this by right-clicking on the file and then pressing Create Shortcut. You have to move this shortcut into the Autostart folder.

To do this, open the Run window by pressing Windows key + R. In the window that appears type shell:startup on. Now move the shortcut into the opened folder. Now the file will start automatically every time you start your PC.

AutoHotkey icon in taskbar
AutoHotkey icon (green H) in the taskbar symbolizes that the script is active and can be stopped here if necessary

But now to the actual part of the script. Open the file with the editor of your choice, for example Notepad++ or Visual Studio Code or other tools.

The script

#Requires AutoHotkey v2.0
; ======================================================================================================================
; Everything until the first `return` autoruns

; ======================================================================================================================
; Function definition. Changes Audio Output Device to `device`
; ======================================================================================================================


ChangeAudioOutput(device, show_msg_box:=true)
{
    symbols := Map("Kopfhörer", "🎧", "Lautsprecher", "🔊", "LG-TV", "📺️")  ; Python dict-like object, callable by `Val := Array[Key]`
    if (show_msg_box)
        symbol := symbols[device]
        {
            ; Show a message box
            MsgBox(
                ; MsgBox's message in the box
                "Selected device: " symbols[device] device,
                ; MsgBox's title/heading
                "Audio Output Device changed",
                ; time after which the MsgBox will close
                "T0.3"
                )
        }
    Run("C:\Windows\nircmd.exe setdefaultsounddevice " device)  ; change device using nircmd
}

; set Speakers as default device for startup
;ChangeAudioOutput("Lautsprecher", false)  ; false -> don't show message box at startup
return  ; Everything above this `return` autoruns
; ======================================================================================================================



; ======================================================================================================================
; Audio Output Device Switch to Speakers/Headphones/TV
; ======================================================================================================================
; Audio Output Device Switch to Speakers
; ~ means passthrough for the Hotkey so others programs can use it too (in this case MonitorSwitcher)
~^+F1:: ; Strg + Umschalt + F1
{
	Run '"C:\Program Files\MonitorProfileSwitcher\MonitorSwitcher.exe" -load:"C:\Users\Sascha\AppData\Roaming\MonitorSwitcher\Profiles\PC-Main-only.xml"'
    ChangeAudioOutput('Lautsprecher')
}

; Audio Output Device Switch to Headphones
~^+F2:: ; Strg + Umschalt + F2
{
	Run '"C:\Program Files\MonitorProfileSwitcher\MonitorSwitcher.exe" -load:"C:\Users\Sascha\AppData\Roaming\MonitorSwitcher\Profiles\TV-only.xml"'
    ChangeAudioOutput('Kopfhörer')
}

; Audio Output Device Switch to TV
~^+F3:: ; Strg + Umschalt + F3
{
	Run '"C:\Program Files\MonitorProfileSwitcher\MonitorSwitcher.exe" -load:"C:\Users\Sascha\AppData\Roaming\MonitorSwitcher\Profiles\PC-Main+Fernseher.xml"'
    ChangeAudioOutput('LG-TV')
}

Explanation of the script parts

Much of the script can be easily copied if the previous steps are followed. Lines starting with ; begin are comment lines and are not executed. If you remove the semicolon at the line below the line ; set Speakers as default device for startup is removed, the audio device will be changed to the one specified there every time the system is started or the script is started (not pressing a hotkey). As it says there everything above this return command is executed automatically. You can also add more.

The ChangeAudioOutput method changes the audio output via the nircmd tool. The method also maps the names of the audio devices to icons that are shown in the popup window when you press the hotkey. The important part now is that the audio devices get the names of your audio devices. The audio devices must not contain spaces in the name! Open your sound settings and see what your devices sound like. For example, speakers or your headset the Corsair-XYZ, which you can then rename headphones. You can also keep Corsair-XYZ as the name and then you have to replace Headphones with Corsair-XYZ everywhere in the script.

Now for the cryptic terms, but they are also explained in the script. ~^+F1:: means that the hotkey is set to Ctrl + Shift + F1 is located. This means that the command anchored in it will be executed when it is triggered. You can also assign a completely different hotkey. How to do that, you can read here at the AutoHotkey definitions read about it. The same applies to the other two hotkeys given.

Still important is the Run command, which calls MonitorSwitcher and the respective profile: Run '"C:\Program Files\MonitorProfileSwitcher\MonitorSwitcher.exe" -load: "C:\Users\Sascha\AppData\Roaming\MonitorSwitcher\Profiles\TV-only.xml"'

As already mentioned, your profiles are always located under C:\Users\\AppData\Roaming\MonitorSwitcher\Profiles\ and you only need to add the name of your profile, as in the case of TV-only.xml. And of course the exchange of <Benutzer> with your username do not forget. That's all the magic and you can start using the hotkeys!

Conclusion

Setting up and switching between different monitor and audio configurations can be a time-consuming task, especially if you use multiple monitors and audio devices. This can be especially annoying if you frequently switch between different setups, for example between a gaming setup and a work setup.

One solution to this problem is to use a script that allows switching between different monitor profiles and audio output devices using a keyboard shortcut. This makes it much easier to switch between different configurations without having to navigate through the Windows menus each time.

The basis for this script consists of several tools, including AutoHotkey, nircmd and MonitorProfileSwitcher. AutoHotkey allows you to create hotkeys that let you quickly switch the configurations you want. The nircmd is used to change the audio output devices and MonitorProfileSwitcher helps manage the monitor profiles.

Overall, this script provides partial automation to avoid the hassle of manually adjusting configurations. It is especially useful when using different setups with multiple monitors and audio devices and having to switch between them regularly.

One more hint. If you have a keyboard with extra keys, such as the G1 to G6 from Logitech, you can place the shortcuts / hotkeys directly on it with the software and make your life even easier.


0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

en_US