Switch the screen programs are shown on

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
hotkeyuser1234
Posts: 92
Joined: 07 Mar 2020, 12:27

Switch the screen programs are shown on

08 Aug 2020, 16:28

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!
User avatar
littlegandhi1199
Posts: 195
Joined: 29 Aug 2016, 23:58

Re: Switch the screen programs are shown on

12 Aug 2020, 20:15

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]
Script Backups on every Execution :mrgreen:
https://www.autohotkey.com/boards/viewtopic.php?f=6&t=75767&p=328155#p328155

Scrabble Solver 4-15 letter word outputs ( :crazy: # of inputs)
https://www.autohotkey.com/boards/viewtopic.php?f=19&t=34285
hotkeyuser1234
Posts: 92
Joined: 07 Mar 2020, 12:27

Re: Switch the screen programs are shown on

13 Aug 2020, 15:45

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!
User avatar
littlegandhi1199
Posts: 195
Joined: 29 Aug 2016, 23:58

Re: Switch the screen programs are shown on

13 Aug 2020, 15:49

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
Script Backups on every Execution :mrgreen:
https://www.autohotkey.com/boards/viewtopic.php?f=6&t=75767&p=328155#p328155

Scrabble Solver 4-15 letter word outputs ( :crazy: # of inputs)
https://www.autohotkey.com/boards/viewtopic.php?f=19&t=34285

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Rohwedder, Tech Stuff and 311 guests