Shortcut to switch main display

5,393

Solution 1

With the suggestion of @harrymc and help over at Stack Overflow, I wrote the following bat script which can switch between monitors. In my case display 1 is the default and it switches with display 3 whenever the script is executed.

@echo off
SETLOCAL EnableDelayedExpansion
IF EXIST active.txt (
    set /p display=< active.txt
    del active.txt
    IF "!display!" == "1" (
        nircmd.exe setprimarydisplay 3
        echo | set /P ="3"> "active.txt" 
    ) ELSE (
        nircmd.exe setprimarydisplay 1
        echo | set /P ="1"> "active.txt" 
    )
) ELSE (
    nircmd.exe setprimarydisplay 1
    echo | set /P ="1"> "active.txt" 
)

Save this script in a folder, e.g. C:\tools\switch_display\switch.bat and make sure that you also have nircmd.exe in that directory. You can then create a shortcut on your desktop to that script.

Solution 2

If a window ended up on the wrong monitor and the desktop is in extend mode, you may use Win+Shift+Arrow to move the active window left/right to previous/next monitor.

If you would like to change the primary monitor, you need to use a third-party product.

Below are some such free products. Where monitor number is used, you will need to find out, even by trial and error, what are the numbers for your monitors.

All these products have a command-line mode, so you could use batch scripts. The scripts could be launched by icons on the desktop that may also have assigned hotkeys for easier usage.

Share:
5,393

Related videos on Youtube

Bram Vanroy
Author by

Bram Vanroy

Currently working on machine translation and translation difficulty. I'm also interested in a couple of other things, such as linguistics; natural language processing; artificial intelligence, deep learning; music, drums and bass more specifically; design &amp; UI.

Updated on September 18, 2022

Comments

  • Bram Vanroy
    Bram Vanroy almost 2 years

    I have my TV hooked up to my PC, which also has its own monitors. I have a controller and wireless keyboard attached to the PC with Bluetooth when I control the PC from my couch, and a wired keyboard and mouse when I am at my desk. This set up woks great, except for the settings for the main monitor.

    When I am on the couch and want to launch a program, it will launch on the main monitor (which is set to the monitor on my desk). That is not ideal, so I would want to be able to easily and seamlessly switch between main monitors. I am sure that there must be a command for this, in which case I can just add shortcuts to my desktop which, when clicked, switches the main monitor. I am looking for a bat, cmd, powershell kinda approach and would like to avoid third party software.

    Can anyone help me out with that? Thanks

    • harrymc
      harrymc almost 4 years
      If the monitors are defined as part of the desktop in Extend mode, you may use Windows+Shift+arrow to move the active window left/right to previous/next monitor. More elaborate operations are possible using AutoHotKey.
    • Bram Vanroy
      Bram Vanroy almost 4 years
      @harrymc Thanks, that works as a workaround but is not very convenient in the long run. I think the best way is to explicitly set the main window, but I am not sure what the command is for this.
    • harrymc
      harrymc almost 4 years
      What do you mean by "explicitly set the main window"?
    • Bram Vanroy
      Bram Vanroy almost 4 years
      Oops, I meant the main display.
    • harrymc
      harrymc almost 4 years
      Trying to define it better: Do you wish to set new programs to launch on another monitor than the primary one temporarily until you unset it?
    • Bram Vanroy
      Bram Vanroy almost 4 years
      I just want the same behaviour as you would have by going to display settings > set display as main display. This includes: sets default display where programs our launched, position of start menu, position of right tray in task bar.
  • Bram Vanroy
    Bram Vanroy almost 4 years
    Thanks. Full solution in my answer although I am giving the bounty to you for the inspiration.
  • Admin
    Admin about 2 years
    Tip for nircmd.exe. Maybe it will be useful to someone: if you have several video cards (perhaps this is true for one video card), the display numbers are the number of slots for video cards. For example: the first video card (in the first PCI-Express slot) has 4 ports. I connect the monitor to the first slot. The second card also has 4 slots. I connect monitors to the two left slots. "nircmd.exe setprimarydisplay" takes the values ​​1,5,6 accordingly. "nircmd.exe setprimarydisplay 6 " will set third monitor as primary. I'm using Win10.