Use AHK to halt/pause/stop Windows while going to sleep/hibernate

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
gabidanpremier
Posts: 3
Joined: 19 Dec 2022, 09:15

Use AHK to halt/pause/stop Windows while going to sleep/hibernate

Post by gabidanpremier » 19 Dec 2022, 09:24

Hi,

I've been using AHK with great success since 2014, thanks to this forum. Thank you all :)

I'm using AHK to send RS-232 commands when my script detects the computer is going to sleep. The issue I have now is that sometimes sending these commands take a little longer than the time the computer requires to actually going to sleep. So the commands are not sent properly. Here's what's happening:

1- I ask to go to sleep (requires ~10 seconds)
2- The AHK detects the computer goes to sleep
3- The AHK scripts starts sending the RS-232 commands (which would require ~15 seconds)
4- The computer actually goes to sleep
5- The RS-232 commands aren't sent properly :(

I'm looking for a simple method to either :
- Halt the computer while going to sleep and only until I give him permission to continue.
- Add a delay (let's say 20 seconds) to the process of going to sleep (this could be using AHK or not).

I've been searching a bit about this, I don't have a clue. Can somebody direct me to a path or help me?

Best regards,
Gabriel

User avatar
mikeyww
Posts: 26599
Joined: 09 Sep 2014, 18:38

Re: Use AHK to halt/pause/stop Windows while going to sleep/hibernate

Post by mikeyww » 19 Dec 2022, 09:56

Welcome to this AutoHotkey forum!

You can use AHK for both the commands and then the sleep-- in that order.

gabidanpremier
Posts: 3
Joined: 19 Dec 2022, 09:15

Re: Use AHK to halt/pause/stop Windows while going to sleep/hibernate

Post by gabidanpremier » 19 Dec 2022, 17:15

Indeed mikeyww, thanks for this idea, but it doesn't work in my case.

The shutdown/sleep/hibernate isn't handled by AHK. I want to detect the shutdown/sleep/hibernate launched by Windows (using the start menu, after couple of hours through the energy management policies, etc.).

I know sometimes there are software that can't be killed and halt the shutdown process (for example an unsaved notepad file will halt the shutdown on a "Save" prompt). Could AHK have a "do not kill right now" rule?

Other ideas?

BR,
Gab

User avatar
mikeyww
Posts: 26599
Joined: 09 Sep 2014, 18:38

Re: Use AHK to halt/pause/stop Windows while going to sleep/hibernate

Post by mikeyww » 19 Dec 2022, 17:31

That's not actually what your original post says. It reads
I ask to go to sleep
I believe that your question is how you can interrupt a sleep in progress to get your script executed. Sorry I do not have an answer in that circumstance where you are not asking your computer to sleep, but it sleeps anyway. There are ways to run commands at shutdown, and ways to abort shutdown, but this differs from sleep. Sleep is also not halted by unsaved work, because the "state" of the memory is saved as power is not actually fully relinquished in a sleep state.

Others here may have more info for you.

gabidanpremier
Posts: 3
Joined: 19 Dec 2022, 09:15

Re: Use AHK to halt/pause/stop Windows while going to sleep/hibernate

Post by gabidanpremier » 21 Dec 2022, 09:47

mikeyww

Indeed, I wasn't clear.

Thanks for your help, I'll find a workaround :) It won't be OS-based, sadly, which was what I was looking for.

piterx
Posts: 1
Joined: 25 Mar 2023, 03:01

Re: Use AHK to halt/pause/stop Windows while going to sleep/hibernate

Post by piterx » 25 Mar 2023, 03:03

Could you share how you send commands to RS232?
Thannks.
Petro

Post Reply

Return to “Ask for Help (v1)”