Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sleep/suspend/hibernate computer with a keyboard shortcut using AutoHotKey
; This is part of my AutoHotkey [1] script that puts my computer to sleep when I
; press Win+F12.
; I chose that keyboard shortcut because it's very similar to the Fn+F12
; keyboard shortcut on my laptop.
; I don't have my PC set to require a password to resume, so I also have a
; second version (Win+Shift+F12) in case I want to lock the PC first.
; [1]: http://www.autohotkey.com/
; Win+F12 - Sleep
#F12::
; Sleep/Suspend:
DllCall("PowrProf\SetSuspendState", "int", 0, "int", 0, "int", 0)
; Hibernate:
;DllCall("PowrProf\SetSuspendState", "int", 1, "int", 0, "int", 0)
Return
; Win+Shift+F12 - Lock and sleep
#+F12::
; Lock:
Run rundll32.exe user32.dll`,LockWorkStation
Sleep 1000
; Sleep/Suspend:
DllCall("PowrProf\SetSuspendState", "int", 0, "int", 0, "int", 0)
; Hibernate:
;DllCall("PowrProf\SetSuspendState", "int", 1, "int", 0, "int", 0)
Return
@DimensionalScoop

This comment has been minimized.

Copy link

DimensionalScoop commented May 13, 2013

Just what I have been looking for!

@pilotmaks

This comment has been minimized.

Copy link

pilotmaks commented May 16, 2014

Thanks !!! ))

@nguyen14

This comment has been minimized.

Copy link

nguyen14 commented Aug 14, 2014

sign up just to say thanks!

@Uzer1

This comment has been minimized.

Copy link

Uzer1 commented Sep 30, 2014

It saved me some time on doing it myself. Thanks.

@oroalej

This comment has been minimized.

Copy link

oroalej commented Jan 1, 2015

Thank you very much! I've been searching for this for hours! 😄

@cdonate

This comment has been minimized.

Copy link

cdonate commented Feb 23, 2015

Thanks, just what I was looking for. Nicely done.

@pondermatic

This comment has been minimized.

Copy link

pondermatic commented May 21, 2015

Terrific! Thank you.

@ryancwalsh

This comment has been minimized.

Copy link

ryancwalsh commented Nov 6, 2015

Thanks so much!

@rstolper

This comment has been minimized.

Copy link

rstolper commented Apr 2, 2016

Thanks!

@seanspotatobusiness

This comment has been minimized.

Copy link

seanspotatobusiness commented Jul 12, 2017

Is it possible to modify so that F12 has to be pressed, released and pressed a second time?

@OPKS

This comment has been minimized.

Copy link

OPKS commented Aug 26, 2017

Thanks! Exactly what I needed.

@maxpereira

This comment has been minimized.

Copy link

maxpereira commented Jun 7, 2018

thanks very much!

@ghost

This comment has been minimized.

Copy link

ghost commented Sep 16, 2018

¡Muchas gracias! Muy útil

@ghost

This comment has been minimized.

Copy link

ghost commented Oct 15, 2018

How to quickly restart windows ?

@YakovL

This comment has been minimized.

Copy link

YakovL commented Dec 7, 2019

This still works in 2019, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.