Thanks a lot to all for your posts. You are quicker in writing that I can read the (long) links and test them. I'm slow because my English is not the best and this all is completely new and hard stuff for me. I will try and report your suggestions piece by piece...
If you prefer to do it from command line, this is working here on Debian 11 (Ubuntu is a fork of Debian):
To disable hibernate and suspend use the following command:
sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
To re-enable hibernate and suspend use the following command:
sudo systemctl unmask sleep.target suspend.target hibernate.target hybrid-sleep.target
I tried this suggestion and after 20 minutes the system did not enter Standby, but my console session got lost (disappeared) and the Login screen was displayed, where I had to enter my password, although this is configured not to be neccessary. After login the system needed 45 seconds to draw the desktop. Tested 2 times => not usable on my system.
Did you try with root privilege?
sudo systemd-inhibit <my_program>
Now I tried with sudo: after 20 minutes the system did not enter Standby, but a dialog appeared (see screenshot) to enter sudo password => not usable for me.
... but maybe moving the mouse with something like this:
var
MousePos: TPoint;
...
MousePos := Mouse.CursorPos;
MousePos.X := MousePos.X + 10;
MousePos.Y := MousePos.Y + 10 ;
Mouse.CursorPos := MousePos;
sleep(10);
MousePos.X := MousePos.X - 10;
MousePos.Y := MousePos.Y - 10 ;
Mouse.CursorPos := MousePos;
I made a litte demo and it worked!
const stop: boolean = false;
procedure TForm1.Button_StartClick(Sender: TObject);
var mp: TPoint;
d: integer;
begin
d:=0; {'0' works on Ubuntu 18.04 with KDE desktop}
repeat
mp:=Mouse.CursorPos;
inc(mp.x,d);
inc(mp.y,d);
Mouse.CursorPos:=mp;
Application.ProcessMessages;
sleep(2000);
d:=-d;
until stop;
Close;
end;
procedure TForm1.Button_CloseClick(Sender: TObject);
begin
stop:=true;
end;
I reduced var 'd' until zero pixels and it still worked! So only command "Mouse.CursorPos:=mp;" does prevent the system from entering Standby.
Thank you very much Fred vS for this idea! A benefit is, that no system settings have to be changed (and later restored!). And no sudo is needed :-) A side effect is, that the monitor does not go to sleep any longer (no problem for me).
It does *not* work on Windows 10 (not even with 'd:=10'), but I'm now only interested on Linux.
But a problem is, that I didn't manage to adapt this mouse solution into a console program. Here is my attempt:
uses sysutils, crt, Mouse;
procedure Test_Maus;
var d,x,y: integer;
begin
InitMouse;
write(DetectMouse, ' Buttons '); {returns "2 Buttons"}
ShowMouse;
d:=10;
repeat
x:=GetMouseX;
y:=GetMouseY;
write(x, '/', y, '':2); {is ALWAYS 2x zero!!}
inc(x,d); inc(y,d);
SetMouseXY(x,y); {seems to do nothing}
sleep(2000);
d:=-d;
until keypressed;
DoneMouse;
end;
The problem is: GetMouseX() and GetMouseY() both ALWAYS return '0' => when 'd' is negative, an exception occurs.
What do I make wrong?
Is there another (better) way to access the mouse in a console program?Meanwhile I'll have a look at the other suggestions...