[SOLVED] How to prevent Linux to enter Standby while my program is running? lazarus / 32-Linux ---------------------------------------------------------------------- Hartmut · 2021-10-10 11:57 While my program runs, I want to prevent that the computer enters Standby mode after 20 minutes, as usual. It does not matter, if the monitor goes to sleep or not. I found https://forum.lazarus.freepascal.org/index.php/topic,53143.0.html and walked through it, but found no "solution" in there. Because every mp3- or video-player needs this function, I assume that Linux must provide a way for that. Either via some kind of "System Call" or a "command line tool". Does someone of the Linux experts know such a "System Call" or command line tool? I need a solution for Ubuntu 18.04 (with KDE Desktop, if that matters). Thanks in advance. ---------------------------------------------------------------------- Wallaby · 2021-10-10 12:24 It's called Inhibit lock: https://www.freedesktop.org/wiki/Software/systemd/inhibit/ If you want a command line tool, then systemd-inhibit: https://www.freedesktop.org/software/systemd/man/systemd-inhibit.html ---------------------------------------------------------------------- Fred vS · 2021-10-10 13:02 Hello. In console (or use a TProcess) do this: Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i xset -dpmsxset s off ---------------------------------------------------------------------- Hartmut · 2021-10-10 16:05 Quote from: Wallaby on October 10, 2021, 02:24:47 pmIt's called Inhibit lock: https://www.freedesktop.org/wiki/Software/systemd/inhibit/ If you want a command line tool, then systemd-inhibit: https://www.freedesktop.org/software/systemd/man/systemd-inhibit.html Thank you very much Wallaby for that 2 links. The first seems to be what I need, but I'm a bit helpless how and where to start. The documentation is very large (and has a lot of links with other links) but this is hard stuff and I did not understand very much how to access that thing from Free Pascal. Is there a class or a unit which I can use? I tried units Baseunix, Linux and Unix but didn't find procedure Inhibit() there. Can you please give me more infos how to access that thing? I'm a bloody beginner to that kind of stuff... If I understood your second link correctly, it is not possible to call this solution from a program, because the program is called by command "systemd-inhibit". My program has only 1 possible function, which needs to prevent Standby, but not for the whole program. So I need something, which I can call at the beginning of this special function. Quote from: Fred vS on October 10, 2021, 03:02:01 pmIn console (or use a TProcess) do this: Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i xset -dpmsxset s off Thanks Fred vS for that idea. I tried it from a console, but unfortunately it didn't work. It made the monitor not going to sleep after 15 minutes, but Standby was entered 5 minutes later as usual. I'm only looking for preventing Standby, not the monitor. ---------------------------------------------------------------------- Fred vS · 2021-10-10 16:24 Quote from: Hartmut on October 10, 2021, 06:05:09 pmThanks Fred vS for that idea. I tried it from a console, but unfortunately it didn't work. It made the monitor not going to sleep after 15 minutes, but Standby was entered 5 minutes later as usual. I'm only looking for preventing Standby, not the monitor. Ha ok, then why dont you use simply the Settings-Power Management applet and disable "Suspend" ? ---------------------------------------------------------------------- Fred vS · 2021-10-10 16:40 Quote from: Fred vS on October 10, 2021, 06:24:46 pmQuote from: Hartmut on October 10, 2021, 06:05:09 pmThanks Fred vS for that idea. I tried it from a console, but unfortunately it didn't work. It made the monitor not going to sleep after 15 minutes, but Standby was entered 5 minutes later as usual. I'm only looking for preventing Standby, not the monitor. Ha ok, then why dont you use simply the Settings-Power Management applet and disable "Suspend" ? 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: Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i sudo systemctl mask sleep.target suspend.target hibernate.target hybrid- sleep.target To re-enable hibernate and suspend use the following command: Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i sudo systemctl unmask sleep.target suspend.target hibernate.target hybrid- sleep.target ---------------------------------------------------------------------- Hartmut · 2021-10-10 17:20 Quote from: Fred vS on October 10, 2021, 06:24:46 pmHa ok, then why dont you use simply the Settings-Power Management applet and disable "Suspend" ? This would need every time:  - half a dozen mouse-clicks to disable Standby  - half a dozen mouse-clicks to re-enable Standby after my program finished  - and I would forget at least one of both every 5th time... This would be extremely uncomfortable and unsure. If I would want something like this, I would not have asked in this forum ;-) Quote from: Fred vS on October 10, 2021, 06:40:58 pmIf 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: Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i sudo systemctl mask sleep.target suspend.target hibernate.target hybrid- sleep.target To re-enable hibernate and suspend use the following command: Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i sudo systemctl unmask sleep.target suspend.target hibernate.target hybrid- sleep.target Thanks a lot for that interesting suggestion, but unfortunately it needs sudo. It would be very uncomfortable, if I had to start my program always with password with a chance of only 5% to 10% that to prevent from Standby is really needed. Every mp3- and video-player does this job without needing sudo, so there must be a better way... ---------------------------------------------------------------------- Hartmut · 2021-10-10 17:27 Quote from: Wallaby on October 10, 2021, 02:24:47 pmIf you want a command line tool, then systemd-inhibit: https://www.freedesktop.org/software/systemd/man/systemd-inhibit.html I tried it in a console:    systemd-inhibit which from the Example in your link should "inhibit system sleeping, shutdown and idle". But it did not work, the computer entered Standby as usual :-(( Does anybody have an idea, why this does not work on my Ubuntu 18.04 (with KDE Desktop, if that matters)? Does it make sense, to follow this suggestion: Quote from: Wallaby on October 10, 2021, 02:24:47 pmIt's called Inhibit lock: https://www.freedesktop.org/wiki/Software/systemd/inhibit/ if console command "systemd-inhibit" does *not* work on my system? ---------------------------------------------------------------------- Fred vS · 2021-10-10 17:47 Quote from: Hartmut on October 10, 2021, 07:27:12 pmDoes anybody have an idea, why this does not work on my Ubuntu 18.04 (with KDE Desktop, if that matters)? Does it make sense, to follow this suggestion: Quote from: Wallaby on October 10, 2021, 02:24:47 pmIt's called Inhibit lock: https://www.freedesktop.org/wiki/Software/systemd/inhibit/ if console command "systemd-inhibit" does *not* work on my system? Did you try with root privilege? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i sudo systemd-inhibit ---------------------------------------------------------------------- Fred vS · 2021-10-10 17:59 Hello. Sorry but I dont see console solution without sudo. [EDIT] Maybe this one: https://superuser.com/questions/1413107/how-to- use-systemd-inhibit-without-sudo Maybe you could think about a workaround to reset the counter of suspend? Something like creating the same dummy file with filecreate() every 3 minutes ? [EDIT] Not sure that creating file reset idle but maybe moving the mouse with something like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     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;  this with a timer duration 10 minutes? And reset this timer each time the user do something in your program. Not the most academical way but it should work. ---------------------------------------------------------------------- Gustavo 'Gus' Carreno · 2021-10-10 23:42 Hey Hartmut, Quote from: Hartmut on October 10, 2021, 01:57:49 pmI need a solution for Ubuntu 18.04 (with KDE Desktop, if that matters). Thanks in advance. Did a very quick search on Google and found this answer on Stack Overflow: [Answer] How to programmatically prevent linux computer from sleeping or turning on screensaver? The question is a bit misleading when you're thinking about media players, but the answer actually mentions that he looked at mplayer and SDL when he searched for a solution. One of the things he mentions is using DBus to access the Inhibit thingamaboob. Around 5 years ago I created this repo on GitHub with some code to access DBus: fpdbus-tools. All of the code I've posted there is just a copy of the code that Michaël Van Canneyt created along side his article on DBus. In those tools you have a DBus explorer and a tool to create the stubs(pascal code) to access the thing you're after. I had a bit of a go at using it but didn't quite got past the whole magic of it all, so I'm completely useless if you want help on it, very sorry. Hope this helps, or at least gets you unstuck Cheers, Gus ---------------------------------------------------------------------- Gustavo 'Gus' Carreno · 2021-10-10 23:56 Hey Hartmut, If you decide to take the Dbus route, I've found a bit more info while using the title of the first question in Google: Prevent system from going to sleep/suspend - how Xviewer/VLC do it. The answer that is marked as the solution details a lot of the DBus chatter that Firefox and VLC do when they have to disable the screensaver/suspend. Didn't read it all, but I found it long enough, that I'm guessing that it contains enough information to get you started if you would want to opt for the DBus solution. On a side note, this would be the way I would implement it. DBus was created for such Desktop Environments agnostic usage, and, while it's a bit complicated to wrap you're head around, seems to function quite well. But don't heed me any attention, cuz this is just my 2 bits opinion on it Cheers, Gus ---------------------------------------------------------------------- Thaddy · 2021-10-11 07:51 Every recent Debian or Debian derived distro (like Ubuntu) contains molly-guard: sudo apt-get install molly-guard. http://manpages.ubuntu.com/manpages/impish/en/man8/molly-guard.8.html Note that there are plenty of other options (editting system.d for one) , but this one is very user friendly. In essence: it does that for you... (Bonus: Molly is very proficient in Pascal too   ) ---------------------------------------------------------------------- Zvoni · 2021-10-11 10:38 I knew the "problem" sounded familiar https://forum.lazarus.freepascal.org/index.php/topic,56307.msg418401.h tml#msg418401 Nota Bene: That's for Windows. Not sure if there is a cross-platform way On a sidenote: Never ever touch Power-Management settings from within your Program ---------------------------------------------------------------------- Hartmut · 2021-10-11 15:07 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... Quote from: Fred vS on October 10, 2021, 06:40:58 pmIf 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: Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i sudo systemctl mask sleep.target suspend.target hibernate.target hybrid- sleep.target To re-enable hibernate and suspend use the following command: Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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. Quote from: Fred vS on October 10, 2021, 07:47:17 pmDid you try with root privilege? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i sudo systemd-inhibit 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. Quote from: Fred vS on October 10, 2021, 07:59:56 pm... but maybe moving the mouse with something like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     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! Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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... ---------------------------------------------------------------------- Fred vS · 2021-10-11 15:29 Quote from: Hartmut on October 11, 2021, 05:07:31 pm Quote from: Fred vS on October 10, 2021, 07:59:56 pm... but maybe moving the mouse with something like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     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! Nice that it worked for you! By the way, thanks for your topic, I did not note that "suspend" possible problem for some of my applications. Thanks to you it is fixed now (using the "simulate mouse move timer" trick). QuoteBut a problem is, that I didn't manage to adapt this mouse solution into a console program. Maybe for console program you should simulate a key-press, not a mouse-move. Fre;D ---------------------------------------------------------------------- Fred vS · 2021-10-11 16:20 QuoteA side effect is, that the monitor does not go to sleep any longer. Ha, yes indeed. Then you could add this at end of your timer-mouse-move-simulator code (with a TProcess): Console command: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i xset dpms force off This will force the os to sleep. And add a method for "onmousemove" in your application that reset the timer when mouse has moved. Now to determinate how long the duration of the timer should be and mimic the delay used by the os-config, sure that you will find a way via google to retrieve that info (or simply set to 3 minutes, it is standard). [EDIT] Or even better, in settings of your app, give the choice of the sleeper time: or no screen-sleep or edited time in minutes. Fre;D ---------------------------------------------------------------------- Hartmut · 2021-10-11 17:12 Quote from: Fred vS on October 11, 2021, 05:29:56 pmQuoteBut a problem is, that I didn't manage to adapt this mouse solution into a console program. Maybe for console program you should simulate a key-press, not a mouse-move. Is it possible to "simulate" keystrokes? How could that be done? Do you think, this would prevent the system entering Standby mode? ---------------------------------------------------------------------- Fred vS · 2021-10-11 17:33 Quote from: Hartmut on October 11, 2021, 07:12:15 pmIs it possible to "simulate" keystrokes? How could that be done? https://wiki.lazarus.freepascal.org/MouseAndKeyInput Quote from: Hartmut on October 11, 2021, 07:12:15 pmDo you think, this would prevent the system entering Standby mode? Yes. ---------------------------------------------------------------------- PascalDragon · 2021-10-12 07:03 Quote from: Fred vS on October 11, 2021, 06:20:56 pmConsole command: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i xset dpms force off This will force the os to sleep. I take it you mean “This will for the monitor to sleep”? ---------------------------------------------------------------------- Hartmut · 2021-10-12 12:44 Quote from: Gustavo 'Gus' Carreno on October 11, 2021, 01:42:24 amDid a very quick search on Google and found this answer on Stack Overflow: [Answer] How to programmatically prevent linux computer from sleeping or turning on screensaver? ...Quote from: Gustavo 'Gus' Carreno on October 11, 2021, 01:56:47 amIf you decide to take the Dbus route, I've found a bit more info while using the title of the first question in Google: Prevent system from going to sleep/suspend - how Xviewer/VLC do it. ... Thanks a lot for your posts. I read your links (and some more) but this stuff is too heavy for my level of experience and to voluminous for my small English. For GUI programs I have a good solution (see reply #14). For console programs I hope to find another way. Thanks again for trying to help me. Quote from: Thaddy on October 11, 2021, 09:51:43 amEvery recent Debian or Debian derived distro (like Ubuntu) contains molly-guard: sudo apt-get install molly-guard. http://manpages.ubuntu.com/manpages/impish/en/man8/molly-guard.8.html ... Thank you Thaddy for this suggestion. I had a look at it but I see no way to solve my problem with it. I don't want to activate Standby mode, I want to prevent the automatic Standby in idle mode from a console program. ---------------------------------------------------------------------- Hartmut · 2021-10-12 13:46 Quote from: Zvoni on October 11, 2021, 12:38:28 pmI knew the "problem" sounded familiar https://forum.lazarus.freepascal.org/index.php/topic,56307.msg418401.h tml#msg418401 Nota Bene: That's for Windows. ... Thanks Zvoni. Yes, SetThreadExecutionState() is only for Windows while I'm looking for a Linux solution. I added a nice alternative for Windows to your Topic. ---------------------------------------------------------------------- Fred vS · 2021-10-12 14:02 Quote from: PascalDragon on October 12, 2021, 09:03:21 amQuote from: Fred vS on October 11, 2021, 06:20:56 pmConsole command: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i xset dpms force off This will force the os to sleep. I take it you mean “This will for the monitor to sleep”? Hello Sven. Yes, not good English, Google translate says this: This will force the system to sleep the screen ---------------------------------------------------------------------- Gustavo 'Gus' Carreno · 2021-10-12 14:48 Hey Hartmut, Quote from: Hartmut on October 12, 2021, 02:44:50 pmThanks a lot for your posts. I read your links (and some more) but this stuff is too heavy for my level of experience and to voluminous for my small English. For GUI programs I have a good solution (see reply #14). For console programs I hope to find another way. Thanks again for trying to help me. You're more than welcome and I don't mind you not opting for my suggestions. I'm quite aware that DBus is not the easiest of APIs to use. I remember that I played a lot with the Browser on that repo I created, but I never got to do any code. Damn thing was too dense for me also I just wanted you to have one more option to choose at Cheers, Gus ---------------------------------------------------------------------- Fred vS · 2021-10-12 16:15 Quote from: Hartmut on October 11, 2021, 05:07:31 pmBut a problem is, that I didn't manage to adapt this mouse solution into a console program. Here is my attempt: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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? Hello Hartmut. I tested your solution (that should work for console program) but, indeed, here on Debian 11, GetMouseX() and GetMouseY() both ALWAYS return '0' . Also not luck with SetMouseXY(). Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program mouseposition;usessysutils, crt, mouse; vardoloop : integer = 0; begin InitMouse; ShowMouse; while doloop < 5 do   begin     sleep(3000);      writeln('Mouse positionXY = ' + inttostr(getmousex) + ',' + inttostr(getmousey)) ;     SetMouseXY(getmousex + 1, getmousey + 1);    inc(doloop);end;  end. Imho there is a bug (or we missed something). Maybe you could create a GitLab fpc-issue. Fre;D ---------------------------------------------------------------------- Hartmut · 2021-10-12 16:57 Quote from: Fred vS on October 11, 2021, 07:33:37 pmQuote from: Hartmut on October 11, 2021, 07:12:15 pmIs it possible to "simulate" keystrokes? How could that be done? https://wiki.lazarus.freepascal.org/MouseAndKeyInput I had a look into this package, but unfortunately every sourcefile uses unit 'Forms', so it will be only usable for GUI programs, while I need something for console programs. But I looked deeper and could extract the "minimal essence" for Linux and it works in a console program - it prevents the system from entering Standby :-)) This is my demo: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$mode objfpc}{$H+}{$linklib Xtst} uses X,XLib,KeySym, sysutils,crt; function XTestFakeKeyEvent(dpy: PDisplay; keycode: dword; is_press: Boolean;                         delay: dword): longint; cdecl; external; procedure KeyDown(KeySym: TKeySym);var  Display: PDisplay;begin  Display := XOpenDisplay(nil);  XTestFakeKeyEvent(Display, XKeysymToKeycode(Display, KeySym), True, 0);  XFlush(Display);  XCloseDisplay(Display);end; procedure KeyUp(KeySym: TKeySym);var  Display: PDisplay;begin  Display := XOpenDisplay(nil);  XTestFakeKeyEvent(Display, XKeysymToKeycode(Display, KeySym), False, 0);  XFlush(Display);  XCloseDisplay(Display);end; procedure KeyPress(KeySym: TKeySym);begin  KeyDown(KeySym);  KeyUp(KeySym);end; procedure no_Standby;begin   repeat write('.');          KeyPress(XK_Shift_L); // simulate left SHIFT key          sleep(2000);   until  keypressed;end; Instead of 'XK_Shift_L' I can use '0' too to avoid conflicts with a typing user. Thanks a lot again to Fred vS for your help. ---------------------------------------------------------------------- Fred vS · 2021-10-12 17:09 Quote from: Hartmut on October 12, 2021, 06:57:17 pmQuote from: Fred vS on October 11, 2021, 07:33:37 pmQuote from: Hartmut on October 11, 2021, 07:12:15 pmIs it possible to "simulate" keystrokes? How could that be done? https://wiki.lazarus.freepascal.org/MouseAndKeyInput I had a look into this package, but unfortunately every sourcefile uses unit 'Forms', so it will be only usable for GUI programs, while I need something for console programs. But I looked deeper and could extract the "minimal essence" for Linux and it works in a console program - it prevents the system from entering Standby :-)) This is my demo: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$mode objfpc}{$H+}{$linklib Xtst} uses X,XLib,KeySym, sysutils,crt; function XTestFakeKeyEvent(dpy: PDisplay; keycode: dword; is_press: Boolean;                         delay: dword): longint; cdecl; external; procedure KeyDown(KeySym: TKeySym);var  Display: PDisplay;begin  Display := XOpenDisplay(nil);  XTestFakeKeyEvent(Display, XKeysymToKeycode(Display, KeySym), True, 0);  XFlush(Display);  XCloseDisplay(Display);end; procedure KeyUp(KeySym: TKeySym);var  Display: PDisplay;begin  Display := XOpenDisplay(nil);  XTestFakeKeyEvent(Display, XKeysymToKeycode(Display, KeySym), False, 0);  XFlush(Display);  XCloseDisplay(Display);end; procedure KeyPress(KeySym: TKeySym);begin  KeyDown(KeySym);  KeyUp(KeySym);end; procedure no_Standby;begin   repeat write('.');          KeyPress(XK_Shift_L); // simulate left SHIFT key          sleep(2000);   until  keypressed;end; Instead of 'XK_Shift_L' I can use '0' too to avoid conflicts with a typing user. Thanks a lot again to Fred vS for your help. Wow, well done! Nice that you found a solution. But, I maintain that your first solution, using SetMouseXY(), should work and that there is a bug in fpc code. It seems that we are not the only one to have same problem: https://www.developpez.net/forums/d2108363/autres- langages/pascal/autres-ide/unite-mouse-getmousex-getmousey- renvoient-0-a/ And if you try the demo-program here, you will have same result: https://www.freepascal.org/~michael/docs- demo/docskimmer/mouse/setmousexy/ Fre;D ---------------------------------------------------------------------- Hartmut · 2021-10-12 17:24 I saw later somewhere in the documentation of unit 'Mouse' that this unit uses text coordinates and works only in programs or consoles in text mode. Maybe this is the reason. Or a not existing / not appropriate mouse driver. ---------------------------------------------------------------------- Fred vS · 2021-10-12 17:32 Quote from: Hartmut on October 12, 2021, 07:24:27 pmI saw later somewhere in the documentation of unit 'Mouse' that this unit uses text coordinates and works only in programs or consoles in text mode. Maybe this is the reason. Or a not existing / not appropriate mouse driver. Hum... maybe (or not). But the demo provided by fpc does not work. ---------------------------------------------------------------------- PascalDragon · 2021-10-13 07:33 Quote from: Hartmut on October 12, 2021, 07:24:27 pmI saw later somewhere in the documentation of unit 'Mouse' that this unit uses text coordinates and works only in programs or consoles in text mode. Maybe this is the reason. Or a not existing / not appropriate mouse driver. Unit Mouse is for console applications. GUI related convenience units are either part of Lazarus or provided by third parties. ---------------------------------------------------------------------- Fred vS · 2021-10-13 09:25 Quote from: PascalDragon on October 13, 2021, 09:33:16 amQuote from: Hartmut on October 12, 2021, 07:24:27 pmI saw later somewhere in the documentation of unit 'Mouse' that this unit uses text coordinates and works only in programs or consoles in text mode. Maybe this is the reason. Or a not existing / not appropriate mouse driver. Unit Mouse is for console applications. GUI related convenience units are either part of Lazarus or provided by third parties. Hello. What is a console application for you? The demo given in fpc doc seems to be a console application but does not work here on Debian 11: https://www.freepascal.org/~michael/docs- demo/docskimmer/mouse/setmousexy/ Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Program Example7;{ Program to demonstrate the SetMouseXY function. }Uses mouse;begin  InitMouse;  Writeln('Click right mouse button to quit.');  SetMouseXY(40,12);  Repeat    Writeln(GetMouseX,',',GetMouseY);    If (GetMouseX>70) then      SetMouseXY(10,GetMouseY);    If (GetMouseY>20) then      SetMouseXY(GetMouseX,5);  Until (GetMouseButtons=MouseRightButton);  DoneMouse;end. ---------------------------------------------------------------------- PascalDragon · 2021-10-13 12:02 Quote from: Fred vS on October 13, 2021, 11:25:35 amWhat is a console application for you? A console application is an application of which the standard input and output have console capabilities, be it a command line interpreter on Windows (cmd, PowerShell, etc.) or a TTY/PTY on *nix. Quote from: Fred vS on October 13, 2021, 11:25:35 amThe demo given in fpc doc seems to be a console application but does not work here on Debian 11: https://www.freepascal.org/~michael/docs- demo/docskimmer/mouse/setmousexy/ That should probably be reported then. ---------------------------------------------------------------------- Fred vS · 2021-10-13 12:08 Quote from: PascalDragon on October 13, 2021, 02:02:06 pmQuote from: Fred vS on October 13, 2021, 11:25:35 amWhat is a console application for you? A console application is an application of which the standard input and output have console capabilities, be it a command line interpreter on Windows (cmd, PowerShell, etc.) or a TTY/PTY on *nix. Ha, so happy that we think the same! Quote from: PascalDragon on October 13, 2021, 02:02:06 pmQuote from: Fred vS on October 13, 2021, 11:25:35 amThe demo given in fpc doc seems to be a console application but does not work here on Debian 11: https://www.freepascal.org/~michael/docs- demo/docskimmer/mouse/setmousexy/ That should probably be reported then. Hum...  Fre;D ---------------------------------------------------------------------- tetrastes · 2021-10-13 21:50 Quote from: Fred vS on October 13, 2021, 11:25:35 amThe demo given in fpc doc seems to be a console application but does not work here on Debian 11: https://www.freepascal.org/~michael/docs- demo/docskimmer/mouse/setmousexy/ Unit mouse.pp at linux uses gpm, so this demo works fine in character- mode console with gpm, but does not in terminal emulators for X. But there must be solution for both gpm and X, as we can see at f.e. Midnight Commander.