@mikeyww I checked hibernation was disabled by opening the start menu and clicking the power button to see if the hibernate option was available.
Ok, after an hour or two of testing different key combos and exploring the documentation, I finally got something that works 100% of the time:
Code: Select all
#s Up::
Sleep 500
SendMessage, 0x112, 0xF170, 2,, Program Manager
return
Explanation: Basically, the
SoundBeeps that were present in the previous working script were just serving as delays to give the user enough time to release the hotkeys before the actual
SendMessage command went through. (You could actually replace all the
SoundBeeps with just a single
SoundBeep, 37, 300 before the SendMessage call and the previous script would still work). The problem with not including the
Soundbeeps is that as soon as you pressed the hotkey, the
SendMessage call would execute. Then, within a few ms, you would take your fingers off the keyboard to release the hotkey and those "key releases" would register as key-up events in Windows, and thus Windows would immediately cancel trying to go into sleep mode.
I just adjusted the script to only run after the
s key is released, by then which any normal person would be able to release the Windows key as well within 500 ms. After that the
SendMessage goes through and the laptop goes into sleep mode smoothly. You could technically reduce the sleep time to 300 if you press and release hotkeys immediately, but there's no harm in making the script more robust by giving 500 ms to release the hotkey. (addendum: The reason we still need the
Sleep 500 even though we have the
s Up is that you could potentially still hold down the windows key after releasing the
s key, so extra time is required to be sure both keys are released before executing the sleep command)
The only final issue I have with this script (and this new version of Windows modern standby in general) is that if you accidentally wiggle the mouse within 1-2 s of executing the sleep command, Windows cancels trying to go into sleep mode. This is bad UX since it's easy to vibrate the desk slightly while standing up after putting the laptop into sleep mode (especially with high dpi mice like mine's), so I have to practically slide away from my desk like a ninja (or sit there and do nothing for 2-3 s) after putting the laptop to sleep so that I don't accidentally shake the mouse and cancel sleep. (Executing something like
BlockInput, MouseMove does not help since it seems to not impact the mouse-movement detection as the computer goes to sleep. I have already checked the Power Management tab for all HID-compliant mouse devices, and I've also found that that setting only "kicks in" after 4 seconds of the laptop going into sleep mode - you will see the laser pointer go off on the mouse. Before then though, any mouse shake will still cancel sleep mode). Since this new issue is outside the scope of this particular topic, I will not pursue it further here - I will make a new topic if I can't figure out how to perhaps disconnect the mouse before running the sleep command so that a mouse wiggle can't cancel the sleep command.