Reputation: 28188
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.
Upvotes: 22
Views: 17143
Reputation: 1179
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
Upvotes: 0
Reputation: 28188
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
+#Up::
{
Title := WinGetTitle("A")
WinRestore(Title)
X1 := SysGet(76)
Y1 := SysGet(77)
Width := SysGet(78)
Height := SysGet(79)
WinMove(X1, Y1, Width, Height, Title)
}
Upvotes: 36
Reputation: 598
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
Upvotes: 8
Reputation: 71
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
Upvotes: 7