AutoIt: Moving My Display to the Big Screen

Using AutoIt to Change My Display

At my home, we have our desktop connected to both some monitors on my desk and to the 55-inch TV that is wall-mounted above our fireplace (through HDMI). We often play movies on the desktop, but we wanted to be able to watch them on the big screen.  I know there are hotkeys on Windows 7 (the OS we had at the time) that can move the presentation to a different screen (using Windows-P), but the audio did not get moved over.  It would still play on the computer speakers.  I also needed a way for my wife to easily convert from the desktop monitors over to the big screen while I was away at work.  So I created an AutoIt script to automate this to a hotkey.
Using AutoIt to automate keyboard input to monitor switching

AutoIt is a way I found that could perform Windows commands and link them to keyboard input.  You can take a sequence of steps and link them to keys pressed on the keyboard.

Changing the Display

In my case, I needed the Windows-P functionality to change the screen.  This was the easy part.  In moving from the monitor to the TV, I would press Windows-P one or two times.  After that, I could press Windows-P to move back to the desktop one or two more times.  I mapped Ctrl+Space to move to the TV, and I mapped Ctrl+Tab to move back to the desktop.  I set that up in an AutoIt script and tested it.  It worked great!  I could now press Ctrl+Space then Ctrl+Tab to move to my TV then back to my monitors.  Unfortunately, the sound did not change automatically.  We had to have that working for playing videos on the big screen.

Changing the Audio

Volume SettingsI needed to be able to change from, say, “Speakers” in the image to the left, to the “HP” monitor.  (These aren’t actually the devices, but the idea is the same.)  I found some hotkeys in Windows that could open that dialog (the exact hotkeys escapes me now, but it was something like opening the run dialog, typing something, and hitting Enter).

Once that dialog comes up (this was a quick and dirty script, so I just had the AutoIt script wait five seconds after entering the commands to have the speaker dialogue box come up), I just pressed the up arrow key twice and hit Enter.  That made the TV speakers be the selection.  Vice versa to go back to the desktop monitors.

A quick test with the AutoIt script now showed that the audio also transferred when I pressed Ctrl+Space and Ctrl+Tab on the keyboard.

Wrapping It All Up

Now that I had all this in an AutoIt script, I just needed to make sure it started on Windows Startup.  I did something such as moving it to the Startup folder, then tested that I could press Ctrl+Space after a reboot.  It worked!

I then told my wife about the hotkeys, and everything was set!  Now we could both swap easily between the desktop monitors or the big screen without having to manually perform a few steps every time.  It saved probably 30 – 60 seconds each time we used the script, but we swapped back and forth so many times that it probably ended up saving us some hours over the whole time we used that script.  That’s the beauty of automation!  Not just for work, but for everyday life too. 🙂

Leave a Reply

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