July 23, 2016

Quickly Change Windows 10 Resolution with AutoHotkey

I use a 39″ 4K monitor for my computer display because I appreciate a large work surface. Meanwhile, I also like to step away from my desk and use Chrome Remote Desktop on a small 14″ Chromebook to continue my work on the road. So I find myself frequently flipping resolutions, which on Windows 10 is not a simple one-click operation. What I really wanted was the ability to switch resolutions with a single keystroke, and AutoHotkey came to the rescue!

AutoHotkey is an open-source tool for Windows that allows you to automate tasks through text scripts, and map them to any Windows key (as well as joystick and mouse events). The following script maps CTRL-6 through CTRL-9 to different screen resolutions (and refresh rates). To use the script, install AutoHotkey, save the following script to a file with an “.ahk” extension, and then double-click the file. It will execute the script (with an icon in the system tray that you can use to shut it off). You can add the .ahk file to your Startup folder if you want the script to automatically start when you boot:

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.





ChangeResolution( cD, sW, sH, rR ) {
  VarSetCapacity(dM,156,0), NumPut(156,2,&dM,36)
  DllCall( "EnumDisplaySettingsA", UInt,0, UInt,-1, UInt,&dM ), 
  NumPut(cD,dM,104), NumPut(sW,dM,108), NumPut(sH,dM,112), NumPut(rR,dM,120)
  Return DllCall( "ChangeDisplaySettingsA", UInt,&dM, UInt,0 )

To customize this script, you can change the hot keys (“^6” for example means CTRL-6), and change the different resolutions. The parameters to ChangeResolution are:

  • color_depth – The number of bits per pixel for color (leave at 32 for most purposes)
  • width – width of the screen in pixels
  • height – height of the screen in pixels
  • refresh rate – the screen frequency (typically 60Hz, but for some monitors like the Seiki, the 4K resolution is at 30Hz)

I hope this helps you save time!