Hi,
I am working on a little FreeBASIC program, which do not take any keyboard/mouse input. After few minutes of work, my OS (linux) is starting a screensaver, and I have to press any key or move the mouse to get back to my program.
Is there any (hopefully portable) way to prevent the OS from launching any screensaver when my program runs?
How could I temporarily disable screensaver?
From your question I guess that my hope for a portable way is hopeless :-Psir_mud wrote:is this Xscreensaver or a DE provided screensaver utility?
In my case, this is a the KDE power management that shuts my screen off, but it's me - for other users it could be a Gnome screensaver, or a Windows *.scr...
Okay, I looked into the sourcode of VLC (which is able to disable screensaver on my PC), and I found out that it calls simply some commands in a periodic way:
I will have to test if it really works for my program, but it seems to be the way to go, at least on Linux...
Now, what could I do to disable screensaver on Windows?
Code: Select all
xdg-screensaver reset
xscreensaver-command -deactivate
gnome-screensaver-command --poke
Now, what could I do to disable screensaver on Windows?
Hi again,
Here is the code that I am using now to avoid screen saver to happen on my Linux PC (and this code works very well for me!) :)
Now, I am looking for some way to achieve the same thing on Windows...
Is there some winapi crap out there that would allow me to send such fake signals?
Here is the code that I am using now to avoid screen saver to happen on my Linux PC (and this code works very well for me!) :)
Code: Select all
SUB InhibitScreenSaver()
#IFDEF __FB_LINUX__
SHELL "xdg-screensaver reset" ' The supposed "standard" way (which doesn't always work)
SHELL "xscreensaver-command -deactivate" ' The X way
SHELL "qdbus org.freedesktop.ScreenSaver /ScreenSaver SimulateUserActivity" ' The D-BUS way (compatible with KDE4)
SHELL "gnome-screensaver-command --poke" ' The GNOME way
#ENDIF
#IFDEF __FB_WIN32__
#ENDIF
END SUB
Yeah, sure... but how could I send such "faux mouse events"? :-Dvdecampo wrote: On Windows you can periodically send faux mouse or keyboard events to a window. This should fool the screensaver into thinking someone is using the computer.
Is there some winapi crap out there that would allow me to send such fake signals?
Maybe this will work...
Code: Select all
#Include "windows.bi"
'0=Disable / 1=Enable
Function EnableScreenSaver(Enable As Integer) As Integer
Return IIf(SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, Enable, 0, 0) > 0,1,0)
End Function
Thanks! I quickly tested it on a VirtualBox, and it does seem to disable the screensaver indeed!vdecampo wrote:Maybe this will work...Code: Select all
#Include "windows.bi" '0=Disable / 1=Enable Function EnableScreenSaver(Enable As Integer) As Integer Return IIf(SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, Enable, 0, 0) > 0,1,0) End Function
However, this would require to call the function one time when the program starts (to disable the screensaver), and then one time when the program ends (to reenable it). And then, if my program doesn't terminates in a clean way (crash, or killed by the user), then I'm leaving the user without his screensaver... I'd like to avoid that as much as possible. In linux, the idea is to reset the screensaver every now and then, and this seems like a much more nice way to deal with screensaver (so it won't kick in as far as my app is resetting the timer from time to time). Any chance to have such behavior on the Windoze platform maybe? :-P
Add a destructor that is called when the program terminates normally, and don't write code that crashes.. abnormally.Fox wrote:<snip>
And then, if my program doesn't terminates in a clean way (crash, or killed by the user), then I'm leaving the user without his screensaver... I'd like to avoid that as much as possible.
<snip>
Better yet, don't write any Windoze code using that "winapi crap" ;-)