Snap a Window to Top or Bottom of the Screen

Print Page

Microsoft Windows 7 has a handy Snap feature that allows you to arrange open windows, including maximizing and resizing, just by dragging and dropping a window to different edges of the screen. When a window is dragged to the edge, Windows will display a glass overlay on the desktop. As soon as you let go of the mouse button, it will snap the window onto that overlay. This can also be done with keyboard shortcuts:

  • Win+Left: Snap window to the left
  • Win+Right: Snap window to the right
  • Win+Up: Maximize window
  • Win+Down: Restore/Minimize¬†window

But what if you want to snap a window to top half of the screen, and another window on bottom half? There’s no built-in shortcut that does this.

If you are annoyed with this limitation, here’s a AutoHotkey script, by Ben Northway, that will give you these features:

; Move window up
+#Up::
  WinGetPos,X,Y,W,H,A,,,
  WinMaximize
  WinGetPos,TX,TY,TW,TH,ahk_class Shell_TrayWnd,,,

  ; if this is greater than 1, we're on the secondary (right) monitor. This means the center of the active window is a positive X coordinate
  if ( X + W/2 > 0 ) {
  SysGet, MonitorWorkArea, MonitorWorkArea, 1
  WinMove,A,,X,0 , , (MonitorWorkAreaBottom/2)
  }
  else {
  SysGet, MonitorWorkArea, MonitorWorkArea, 2
  WinMove,A,,X,0 , , (MonitorWorkAreaBottom/2)
  }  
return

; Move window down
+#Down::
  WinGetPos,X,Y,W,H,A,,,
  WinMaximize
  WinGetPos,TX,TY,TW,TH,ahk_class Shell_TrayWnd,,,

  ; if this is greater than 1, we're on the secondary (right) monitor. This means the center of the active window is a positive X coordinate
  if ( X + W/2 > 0 ) {
  SysGet, MonitorWorkArea, MonitorWorkArea, 1
  WinMove,A,,X,MonitorWorkAreaBottom/2 , , (MonitorWorkAreaBottom/2)
  }
  else {
  SysGet, MonitorWorkArea, MonitorWorkArea, 2
  WinMove,A,,X,MonitorWorkAreaBottom/2 , , (MonitorWorkAreaBottom/2)
  }
return

With the script running, press these shortcuts:

  • Win+Shift+Up: Snap window to the top
  • Win+Shift+Down: Snap window to the bottom

Snap Window to Top or Bottom

You can customize the script to work with any other keyboard key combinations easily. You just have to edit these two parts in the code: +#Up:: and +#Down::

If you rather have a EXE file, Ben has put it up on his website for download as well.

To run the program with Windows, add a shortcut to the program to your Startup folder on the Start menu.