QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: hanness on December 15, 2021, 07:36:38 am

Title: Looking for a way to prevent sleep while my QB64 program runs
Post by: hanness on December 15, 2021, 07:36:38 am
I have a QB64 program that can take several hours to run. Is there anything that I can put in the code to prevent Windows from going to sleep while the program is running?

I don't want to have to modify my sleep settings every time I run the program. My preference would be to simply have some sort of code within the program that tells Windows not to go to sleep until told otherwise.
Title: Re: Looking for a way to prevent sleep while my QB64 program runs
Post by: SpriggsySpriggs on December 15, 2021, 07:52:07 am
I think there is a way to do this with API but I would have to do some digging.
Title: Re: Looking for a way to prevent sleep while my QB64 program runs
Post by: SMcNeill on December 15, 2021, 08:39:58 am
Simplest way is to just simulate a mouse click onto your program screen every so often.

http://www.qb64.org/wiki/SCREENCLICK

Or _MOUSEMOVE... Just move the mouse a single pixel on the screen.  http://www.qb64.org/wiki/MOUSEMOVE
Title: Re: Looking for a way to prevent sleep while my QB64 program runs
Post by: Dav on December 15, 2021, 09:11:37 am
I've seen code in other languages that use this:
https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setthreadexecutionstate

But the _MOUSEMOVE that Steve mentions sounds like an easier soulution.  Perhaps setup a TIMER/GOSUB to do it every 60 seconds, like ON TIMER (60) GOSUB StayAwake

- Dav

Title: Re: Looking for a way to prevent sleep while my QB64 program runs
Post by: hanness on December 15, 2021, 04:41:00 pm
Thanks for the responses. Much appreciated.