I need it for Windows. I would be very grateful for that! :DPlease check attached project. The program will move the mouse after the system is idle for x seconds.
Please check attached project. The program will move the mouse after the system is idle for x seconds.
Hello!You need the SetThreadExecutionState like this:
I am looking for a way to prevent computer from logging out. It is because I work on a company laptop and I made a program that generates a very long protocol and it takes time to finish. Until it finishes the computer must not log out. (Since this is a company laptop, automatic logging out after 15 min is a default setting and can not be changed.) Right now the only way to prevent it is to move the mouse from time to time but for that I need to keep that in mind and do it again and again.
Does anyone know a way to make this "preventing logging out" automatically? I read something about "SetThreadExecutionState" but I don't now the proper way to use it and couldn't find it on google.
@GemMem: i know this kind of software in pascal since windows have a screensaver :-) Good ShootThanks. I'm using it for years, it works fine.
That was the easter egg. :DPlease check attached project. The program will move the mouse after the system is idle for x seconds.
Line 52 should be like below if you want to set idle time with spinedit (you left hard coded 9 in that line):
if IdleTime > spSec.Value then
Do you know why this occures?When you show your source I can tell whats wrong.
...Put it outside of a method(!)
const
ES_CONTINUOUS = $80000000;
ES_DISPLAY_REQUIRED = $00000002;
ES_SYSTEM_REQUIRED = $00000001;
function SetThreadExecutionState( EXECUTION_STATE : Cardinal ) : Cardinal; stdcall; external 'kernel32.dll' name 'SetThreadExecutionState';[/code]
Docs say, that Prev := SetThreadExecutionState(ES_CONTINUOUS or ES_SYSTEM_REQUIRED or ES_DISPLAY_REQUIRED) is enough, so timer isn't needed. But this state should be manually cleared via SetThreadExecutionState(Prev)....Put it outside of a method(!)
Use it not in a click, use it in a timer(!)
Exemplary:
unit Unit1; {$mode objfpc}{$H+} interface uses Classes , SysUtils , Forms , Controls , Graphics , Dialogs , ExtCtrls; type { TForm1 } TForm1 = class(TForm) Timer1: TTimer; procedure FormCreate(Sender: TObject); procedure Timer1Timer(Sender: TObject); strict private private public end; var Form1: TForm1; implementation {$R *.lfm} const ES_CONTINUOUS = $80000000; ES_DISPLAY_REQUIRED = $00000002; ES_SYSTEM_REQUIRED = $00000001; function SetThreadExecutionState( EXECUTION_STATE : Cardinal ) : Cardinal; stdcall; external 'kernel32.dll' name 'SetThreadExecutionState'; { TForm1 } procedure TForm1.Timer1Timer(Sender: TObject); begin SetThreadExecutionState( ES_SYSTEM_REQUIRED ); SetThreadExecutionState( ES_DISPLAY_REQUIRED ); end; procedure TForm1.FormCreate(Sender: TObject); begin Timer1.Enabled := True; Timer1.Interval := 5000; end; end.
Added to trunk.Good day, than please like that and not my quick and dirty version :-*
so timer isn't neededI do not know to what document you refer, it is just wrong.
have not read all the answersYou not read any answer since what you suggested is already in first reply.
I do not know to what document you refer, it is just wrong.The most obvious docs - are Microsoft's (https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setthreadexecutionstate) ones.
Not believe?
Make a test app that set value just once and do nothing, depending on your power configuration your system will go into power saving mode.