Recent

Author Topic: [CLOSED] Disable screen timeout (display turning off) in Win 10  (Read 2575 times)

pcurtis

  • Hero Member
  • *****
  • Posts: 951
[CLOSED] Disable screen timeout (display turning off) in Win 10
« on: September 16, 2021, 12:47:33 pm »
Hi All,

how can I disable the screen timeout in Windows 10?

Thanks for your help.
« Last Edit: September 16, 2021, 01:34:16 pm by pcurtis »
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

Zvoni

  • Hero Member
  • *****
  • Posts: 2300
Re: Disable screen timeout (display turning off) in Win 10
« Reply #1 on: September 16, 2021, 12:55:14 pm »
This one?
https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setthreadexecutionstate

In your case it would be something like (Aircode)
Code: Pascal  [Select][+][-]
  1. Var
  2.   STES:LongWord; //Or some specific Type, probably an Enum
  3. Begin
  4.    STES:=SetThreadExecutionState(ES_CONTINUOUS Or ES_DISPLAY_REQUIRED);  //Start of "Screen stays online"
  5.   //DoSomething
  6.   STES:=SetThreadExecutionState(ES_CONTINUOUS);  //End of "Screen stays online"
  7. End;
  8.  
« Last Edit: September 16, 2021, 01:00:37 pm by Zvoni »
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: Disable screen timeout (display turning off) in Win 10
« Reply #2 on: September 16, 2021, 01:33:13 pm »
Thanks.

I tried this
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
  2. begin
  3.   SetThreadExecutionState(ES_CONTINUOUS);
  4. end;
  5.  
  6. procedure TForm1.FormCreate(Sender: TObject);
  7. begin
  8.   SetThreadExecutionState(ES_CONTINUOUS OR ES_DISPLAY_REQUIRED);
  9. end;
  10.  
and it seems to work.
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

Zvoni

  • Hero Member
  • *****
  • Posts: 2300
Re: Disable screen timeout (display turning off) in Win 10
« Reply #3 on: September 16, 2021, 01:44:57 pm »
and it seems to work.

Easy to check: Set your Power Management Settings to 1 or 2 Minutes.
Just let your computer idle that time away to make sure that it really turns off your display after that time.
Run your program, and let it run without touching anything (Keyboard, Mouse), and check if Display turns off
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Hartmut

  • Hero Member
  • *****
  • Posts: 739
Re: [CLOSED] Disable screen timeout (display turning off) in Win 10
« Reply #4 on: October 12, 2021, 03:40:39 pm »
For Windows 11, 10, 8.x, 7 and some other Windows there is an alternative: a small nice program (184 kb download) which does this job and many more: "Don't sleep" = http://www.softwareok.com/?seite=Microsoft/DontSleep

It can:
 - prevent the monitor from going to sleep
 - prevent automatic Standby mode
 - come up in an activated state, so no keystrokes or mouse clicks are neccessary after you start it
 - be configured with an INI-file and command line parameters
 - start minimized or in the system tray
 - speak many languages
 - does *not* change any system or registry settings
HTH

 

TinyPortal © 2005-2018