Page 1 of 1

Switch the screen programs are shown on

Posted: 08 Aug 2020, 16:28
by hotkeyuser1234
Dear community,

I often want to switch the screens programs are shown on. For example, I have Chrome on monitor 1 and Excel on monitor 2. Now, I would like to swap this so that Chrome is on monitor 2 and Excel is on monitor 1. How could I do this? I found this thread that might be useful but I do not know how I could adjust the script: https://www.autohotkey.com/boards/viewtopic.php?t=6035

Here you find the two code samples from the thread:
Code 1:

Code: Select all

#Persistent
SysGet, Mon1, MonitorWorkArea, 1
SysGet, Mon2, MonitorWorkArea, 2
SetTimer, MoveBrowsers, 60000
return

MoveBrowsers:
	WinMove, ahk_exe chrome.exe,,Mon1Left, Mon1Top, Mon1Right - Mon1Left, Mon1Bottom - Mon1Top
	WinMove, ahk_exe firefox.exe,,Mon2Left, Mon2Top, Mon2Right - Mon2Left, Mon2Bottom - Mon2Top
return
Code 2:

Code: Select all

OnMessage(0x7E, "OnDisplayChange")

OnDisplayChange() {
    ; Replace the content of this function with whatever.
    SysGet mc, MonitorCount
    Loop % mc {
        SysGet m, Monitor, %A_Index%
        s = %s%`nx %mLeft%:%mRight%  y %mTop%:%mBottom%
    }
    MsgBox Displays changed to:%s%
}
Thank you so much for your help!

Re: Switch the screen programs are shown on

Posted: 12 Aug 2020, 20:15
by littlegandhi1199
Here's an example using Task Manager and Notepad. You press Shift+F10 to swap your 2 target windows.
If you're looking for changing primary monitors which would be capable of doing a lot more then just 2 I might be researching this soon as well.
Let me know.

Use the least specific description of the windows so it catches google chrome even though it's preceeded by the active tab's title and excel with it's currently opened document etc.

"Chrome"
and
"Excel"
might do it but I don't have both to try out for you. *note that it is case sensitive

Code: Select all

SetTitleMatchMode, 2

Win1 = Task Manager
Win2 = Notepad

+F10::
WinGetPos, Win1X, Win1Y, Win1Width, Win1Height, %Win1%
;;msgbox, %Win1%, , %Win1X%, %Win1Y%, %Win1Width%, %Win1Height%

WinGetPos, Win2X, Win2Y, Win2Width, Win2Height, %Win2%
;;msgbox, %Win2%, , %Win2X%, %Win2Y%, %Win2Width%, %Win2Height%

WinMove, %Win1%, , %Win2X%, %Win2Y%, %Win2Width%, %Win2Height%
WinMove, %Win2%, , %Win1X%, %Win1Y%, %Win1Width%, %Win1Height%
return
[code]

Re: Switch the screen programs are shown on

Posted: 13 Aug 2020, 15:45
by hotkeyuser1234
Thank you! I would want it to change any program which I am currently using so please let me know when you continue working on the script.

Thanks!

Re: Switch the screen programs are shown on

Posted: 13 Aug 2020, 15:49
by littlegandhi1199
Primary monitor switching. That's what you'll want to be looking out for I believe.
My AMD GPU software let me set hotkeys to do this.
I have nvidia now and I haven't re-instated it yet.
Also this moves your taskbar to the other screen aswell unless they let you duplicate it these days (and all your desktop icons)
not sure