How can I maximize a window across multiple monitors?
Asked Answered
C

4

22

Using AutoHotkey, How can I bind a hotkey to stretch/maximize/span a window across multiple monitors so that it covers both displays?

Right now, I have to do this by manually stretching the windows with the mouse. I know there are dedicated tools that do this, but I'm already running an AutoHotkey script and would rather limit the number of tools I keep running.

Cyrus answered 22/3, 2012 at 19:2 Comment(0)
C
36

Here's how I did it, mapping the Shift + Windows + Up combination to maximize a window across all displays. This compliments Windows 7's Windows + Up hotkey, which maximizes the selected window.

AHK v1
+#Up::
    WinGetActiveTitle, Title
    WinRestore, %Title%
   SysGet, X1, 76
   SysGet, Y1, 77
   SysGet, Width, 78
   SysGet, Height, 79
   WinMove, %Title%,, X1, Y1, Width, Height
return
AHK v2
+#Up::
{
    Title := WinGetTitle("A")
    WinRestore(Title)
    X1 := SysGet(76)
    Y1 := SysGet(77)
    Width := SysGet(78)
    Height := SysGet(79)
    WinMove(X1, Y1, Width, Height, Title)
}
Cyrus answered 22/3, 2012 at 20:43 Comment(6)
To get this working with the windows VNC client, Settings->Input and uncheck "Pass special keys directly to VNC Server"Colcannon
@kevinf, check the docs on SysGet. 76 = SM_XVIRTUALSCREEN, 77 = SM_YVIRTUALSCREEN, 78 = SM_CXVIRTUALSCREEN, & 79 = SM_CYVIRTUALSCREEN, but there's much more info in the docs about what those values representPterodactyl
this works fine except for fullscreen mode in Netflix, Youtube etc. Then it just takes up 1 screen.Paginate
I have 3 monitors, Is there a way to maximize across only two of them instead?Levison
@Levison You can use custom inputs WinMove, %Title%,, X1, Y1, <width>, <height>. Check this gist out for more info.Ganda
Works great! I made a small adjustment WinMove, %Title%,, X1, Y1, Width, Height-60 so that my taskbar won't be hidden from the window.Monto
B
8

I have two monitors at work and at home with my task bar on the left so I needed to tweak this script to ensure it moved the window correctly.

+#Up::
    WinGetActiveTitle, Title
    WinRestore, %Title%
   SysGet, Mon1, MonitorWorkArea, 1 
   SysGet, Mon2, MonitorWorkArea, 2 
   Monitor1Width := Mon1Right - Mon1Left
   Monitor2Width := Mon2Right - Mon2Left
   MonitorsWidth := Monitor1Width + Monitor2Width
   SysGet, Height, 79
   WinMove, %Title%,, %Mon1Left%, %Mon1Top%, %MonitorsWidth%, %Mon2Bottom%
return

+#Down::
    WinGetActiveTitle, Title
    WinRestore, %Title%
   SysGet, Mon2, MonitorWorkArea, 1
   Monitor1Width := Mon2Right - Mon2Left
   WinMove, %Title%,, %Mon2Left%, %Mon2Top%, %Monitor1Width%, %Mon2Bottom%
return
Bionics answered 23/3, 2016 at 12:10 Comment(0)
L
7

I know this thread is a little old, but this is by far the best "free" way to span maximise across multiple monitors i've been able to find. Ive used it now on both windows 8 and 7 64bit systems and this macro will probably become part of my default toolkit :) Thanks heaps.

And the reason why i'm posting, is i've modified it slightly to restore the window back to a single monitor size, as once the UP macro runs, you will have to manually drag the window back to single sub-monitor size if desired. I've added in a shift+windows+down combo to do this. It could probably be done better remembering the windows old position, but i am not an autohotkey expert, and this works for my purposes... (you could also change the "A_ScreenWidth, A_ScreenHeight" to say 800, 600 for something smaller to work with, and tweak the 0,0 to centre the screen, say 300,200)

Use the autohotkey exe compiler and you have a portable exe to use on another pc. (i.e. my office computer will run the exe fine, but i'd have needed the admin account to install the full program :D )

+#Up::
    WinGetActiveTitle, Title
    WinRestore, %Title%
   SysGet, X1, 76
   SysGet, Y1, 77
   SysGet, Width, 78
   SysGet, Height, 79
   WinMove, %Title%,, X1, Y1, Width, Height
return

+#Down::
    WinGetActiveTitle, Title
    WinRestore, %Title%
   WinMove, %Title%,, 0, 0, A_ScreenWidth, A_ScreenHeight
return
Luncheon answered 29/7, 2013 at 9:50 Comment(1)
This would be significantly better if you saved and restored the original window dimensions upon +#Down rather than toggling between maximized between multiple monitors and maximized on one monitor. Or perhaps better, to override win+down when focused on a spanned maximized window to mirror behavior for native maximized windows.Cyrus
T
0

Derived from the answer by Ciaren Martin above, this is AHK V2 for a setup with taskbar on the left, also monitor 1 is on the right.

;Shift + Windows + Up
+#Up::
{
  title := WinGetTitle("A") 
  WinRestore(title)
  MonitorGetWorkArea(2, &L_Left, &L_Top, &L_Right, &L_Bottom) ; NOTE: Monitor 1 and 2 are switched
  MonitorGetWorkArea(1, &R_Left, &R_Top, &R_Right, &R_Bottom)
  WinMove(L_Left, L_Top, R_Right - L_Left, R_Bottom - L_Top, title)
}

This does not save previous dimensions or location

Tiffany answered 15/5 at 5:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.