3

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 '20 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. – Bram Vanroy Sep 3 '20 at 12:00
  • What do you mean by "explicitly set the main window"? – harrymc Sep 3 '20 at 12:46
  • Oops, I meant the main display. – Bram Vanroy Sep 3 '20 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 '20 at 19:52
1
+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.

1
  • Thanks. Full solution in my answer although I am giving the bounty to you for the inspiration. – Bram Vanroy Sep 4 '20 at 10:55
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.