Create the simplest Windows 7 sleep keyboard shortcut

Create a new text file on the desktop. Paste the following text into it:

Rundll32.exe Powrprof.dll,SetSuspendState Sleep

Save the file as sleep.bat so it becomes a batch file instead of a text file. You may have to disable hibernation.


The following is an Autoit script. Install autoit first, then create a file with the following contents with the .au3 file extension (so like test.au3)

This example uses the s key, but you can change that to whatever key (or keycombo) you want (see the left column of the table you'll see if you scroll down a bit on this page): https://www.autoitscript.com/autoit3/docs/functions/Send.htm

#include<AutoItConstants.au3>

HotKeySet("s", "_Standby")

While 1
    Sleep(10)
WEnd

Func _Standby()
    Shutdown($SD_STANDBY)
EndFunc

If you want to autostart it when the computer runs, rightclick the file and chose Compile script (x86). It will create a .exe file (an executable). Then move that executable to the startup folder, usually located at C:\Users\<user name>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

Note that Windows 7 no longer receives security updates https://support.microsoft.com/en-us/windows/windows-7-support-ended-on-january-14-2020-b75d4580-2cc7-895a-2c9c-1466d9a53962


Using the free AutoHotkey is usually simpler than using Autoit.

The following AutoHotkey script will shutdown the computer on F12:

F12::Run, command-line

You may use for "command-line":

  • nircmd standby
  • wizmo standby
  • SLEEP.EXE

After installing AutoHotKey, put the script in a .ahk file and double-click it to test. You may stop the script by right-click on the green H icon in the traybar and choosing Exit. To have it run on login, place it in the Startup group at C:\Users\USER-NAME\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup.