Author Topic: Looking for a way to prevent sleep while my QB64 program runs  (Read 2793 times)

0 Members and 1 Guest are viewing this topic.

Offline hanness

  • Forum Regular
  • Posts: 210
    • View Profile
Looking for a way to prevent sleep while my QB64 program runs
« 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.

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Looking for a way to prevent sleep while my QB64 program runs
« Reply #1 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.
Shuwatch!

Marked as best answer by hanness on December 15, 2021, 11:41:10 am

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Looking for a way to prevent sleep while my QB64 program runs
« Reply #2 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
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Looking for a way to prevent sleep while my QB64 program runs
« Reply #3 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


Offline hanness

  • Forum Regular
  • Posts: 210
    • View Profile
Re: Looking for a way to prevent sleep while my QB64 program runs
« Reply #4 on: December 15, 2021, 04:41:00 pm »
Thanks for the responses. Much appreciated.