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.

Jeff Axelrod
  • 27,676
  • 31
  • 147
  • 246

3 Answers3

35

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)
}
bogl
  • 1,864
  • 1
  • 15
  • 32
Jeff Axelrod
  • 27,676
  • 31
  • 147
  • 246
  • To get this working with the windows VNC client, Settings->Input and uncheck "Pass special keys directly to VNC Server" – stevesliva Sep 18 '17 at 15:34
  • 1
    @kevinf, check the docs on [`SysGet`](https://www.autohotkey.com/docs/commands/SysGet.htm). `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 represent – KyleMit Aug 28 '19 at 16:32
  • this works fine except for fullscreen mode in Netflix, Youtube etc. Then it just takes up 1 screen. – ndthl Apr 08 '20 at 08:39
  • 3
    I have 3 monitors, Is there a way to maximize across only two of them instead? – BBK Mar 22 '21 at 14:52
  • 2
    @BBK You can use custom inputs `WinMove, %Title%,, X1, Y1, , `. Check [this gist](https://gist.github.com/Zebiano/6798e00ab188c7b23413c92fbeb49c53#gistcomment-3755076) out for more info. – Zebiano May 24 '21 at 15:20
  • 1
    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. – Michael Aug 08 '21 at 22:03
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
Ciaran Martin
  • 578
  • 4
  • 12
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
temporary1
  • 71
  • 1
  • 2
  • 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. – Jeff Axelrod Aug 14 '21 at 14:32