17
votes

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.

3

3 Answers

27
votes

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.

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

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
6
votes

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