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.
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)
If %Width% = 0
Width := W
If %Height% = 0
Height := H
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:
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 800×600.
Resize a Window to a Specific Width
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:
Resize a Window to a Specific Height
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:
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: