4

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

6
  • 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.
    – harrymc
    Sep 3, 2020 at 10:16
  • @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. Sep 3, 2020 at 12:00
  • What do you mean by "explicitly set the main window"?
    – harrymc
    Sep 3, 2020 at 12:46
  • Oops, I meant the main display. Sep 3, 2020 at 15:58
  • 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?
    – harrymc
    Sep 3, 2020 at 19:52

2 Answers 2

2
+200

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.

2
  • Thanks. Full solution in my answer although I am giving the bounty to you for the inspiration. Sep 4, 2020 at 10:55
  • 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.
    – afjord
    May 12, 2022 at 20:00
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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .