• ARTICLES
SEARCH

How-To Geek

Create a Hotkey to Resize Windows to a Specific Size with AutoHotkey

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

image

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 800×600.

#!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:

Download ResizeWindows AutoHotkey Script from howtogeek.com

Lowell Heddings, better known online as the How-To Geek, spends all his free time bringing you fresh geekery on a daily basis. You can follow him on if you'd like.

  • Published 09/16/10

Comments (4)

  1. hdonnell

    Why not just use “Sizer” from brianapps.net. It sizes a window to any size and/or position you desire with a right click of the window any window border.

  2. The Geek

    @hdonnell

    Sizer doesn’t work with 64-bit Windows.

  3. RobCr

    I wonder if i could request another script ?

    There are people in the world that are quite happy to have a view of their folders, with Icons (sometimes large Icons), and the folders snake up and down and left to Right.
    What is the matter with those people ?
    The correct way to view folders, and files, is a vertical list down the screen.
    (With a scrollbar if the list is long.)
    I know we should be tolerant of people’s different preferences, but in this case THEY ARE ALL WRONG.
    Sorry I had to get that off my chest.

    One of the banes of my life is the mini explorer that appears when you are wishing to Save a File. Those dialogs continually show the List view, with it snaking around, and then off to the right of the screen. (Give me a break)
    So you have to go to the Menu, and choose Details.
    I have been doing that for years, and it never remembers the correct view.
    (Some idiot at MS also believes snaking off to the right is a logical navigation.)
    What would be nice would be a script that can change the view to Details.

    Sorry for the rant. Hopefully it might get those that use illogical views in the bigger Windows Explorer, to question the lack of logic for that style.

    PS They may not know that you can use the View Menu to set it to Details, and then go into Tools / Folder Options and then choose the View Tab, and click the button ‘Apply to all Folders’

  4. Dethspark

    script doesnt work with Win vista 32 bit

Enter Your Email Here to Get Access for Free:

Go check your email!