Since I spend a large amount of my time testing out applications, taking screenshots, and doing web development, I’m constantly needing to resize windows to various sizes—so I’ve put together an AutoHotkey function that does it for me. We’re going to assume that you’ve already downloaded and installed AutoHotkey, and you’ve got some type of idea how it all works. If you don’t, you might want to read through their tutorial.

The Scenario

Here’s a sample video that shows the script in action, so you can understand what we’re going to be creating today. The basic idea is that we’ll be resizing windows to specific dimensions, or only resizing by either width or height while leaving the other the same.

Create the AutoHotkey Script

You’ll want to start out by creating a blank AutoHotkey script and putting the following code into it. This is the function that we’ll use to resize windows with some hotkey definitions later on. You can, of course, put this function into your existing script as well.

ResizeWin(Width = 0,Height = 0)
{
  WinGetPos,X,Y,W,H,A
  If %Width% = 0
    Width := W   If %Height% = 0
    Height := H   WinMove,A,,%X%,%Y%,%Width%,%Height%
}

The “A” in the script means that it will work on the active window—you could replace that with the title of a specific window if you wanted. You’ll notice the first line in the function grabs the current width/height and X/Y position, which is then used in the script in case width/height are not set, and to leave the current X/Y position on the screen in the same place.

Resize a Window to Specific Width / Height

This is perhaps the most useful function for web developers, who might want to resize a browser to specific dimensions to test out a page design. Sure, there’s loads of applications and browser plugins that do the same thing, but if you’re an AutoHotkey user all you need is a few extra lines of code to eliminate all that overhead. To resize to a specific width and height, you’ll want to use the function like this:

ResizeWin(width,height)

You can then assign it to a hotkey, in this case we’ll be using Win+Alt+U as the hotkey to resize the current active window to 800x600.

#!u::ResizeWin(800,600)

 
Resize a Window to a Specific Width

image

You can also leave off the height parameter when calling the function to only resize the window width but not the height. This is probably less useful, but I’ve found that it works out well when you have a very large screen and want to resize a number of windows to fit side-by-side on the screen. For instance, this line would assign the Win+Alt+U hotkey to resize the window to 640 pixels wide and leave the height the same:

#!u::ResizeWin(640)

 
Resize a Window to a Specific Height

image

To resize a window to a specific height while leaving the width the same, just pass in 0 as the height parameter. For example, to resize the current window to 400 pixels tall when you press Win+Alt+U, you’d use this line:

#!u::ResizeWin(0,400)

It’s a useful function that you can drop into your AutoHotkey script—even if you don’t need it right now, it’s probably useful to save for later. We’ve also got a downloadable version of the script you can use here:

        <font style="font-size: 11pt" face="Calibri"><a href="https://www.howtogeek.com/wp-content/uploads/gg/up/ResizeWindows.zip">Download ResizeWindows AutoHotkey Script from howtogeek.com</a></font>