Page 1 of 1

How to prevent Windows from Screensaver while program running

Posted: Thu Apr 18, 2019 7:54 pm
by studawg66
I have a Windows app built in LC that I want to disable the screensaver while running. You know, like all of the media player apps disable the screensaver while in "full screen" mode, so that you don't have to wiggle the mouse every 5 minutes while watching a movie. How could I achieve this in LC?

Re: How to prevent Windows from Screensaver while program running

Posted: Thu Apr 18, 2019 9:13 pm
by bogs
Well, let me start off by saying it has been a long LONG time since I used windows for...anything really.

Having said that, from the cli, i remember at one time running a batch file I wrote that killed the screen saver process by simulating a mouse move to 0,0.

I think I'd either try to reconstruct that type of thing if I had the need, or, I'm pretty sure you could move the mouse in Lc (not sure if that qualifies to stop the screen saver though, but sure worth a shot), or possibly it could be as simple as sending a click at a given interval, like every 5 minutes -
Lc Dictionary wrote: click
type
command
syntax

click [button mouseButtonNumber] at point [with key [, key [, key]]]

summary
Simulates a mouse click.

Re: How to prevent Windows from Screensaver while program running

Posted: Thu Apr 18, 2019 9:48 pm
by studawg66
I thought of doing something like that, but was hoping for something a bit more elegant.
I found some information in StackExchange that said there is a function in the Windows API called "SetThreadState" that programs like PowerPoint and Windows Media Player call on for this very task, but not sure how to write that into my LiveCode program.
Is there a way to do a Windows-specific API call in the LC script?

Re: How to prevent Windows from Screensaver while program running

Posted: Thu Apr 18, 2019 10:08 pm
by bogs
Not as far as I know short of writing an external or perhaps running a vbscript, perhaps someone else knows better. Me, I go for what works, I leave extreme elegance to people who understand it :wink:

I did come across this page in Max's excellent wiki though.

*Edit - I did find this little note in rev 2.2x -
Go beyond Transcript
You can extend Revolution's capabilities using XCMDs and XFCNs (on Mac OS and OS X systems) and DLLs (on Windows).

To use an XCMD or XFCN, copy it to the stack's resource fork. To use a DLL, refer to it using the "externals" property. You can use external commands and functions in your scripts, the same as built-in Transcript commands and functions.
.. so maybe?

**Edit 2 - I also hit these pages on SOT (man I love that site) -
http://www.sonsothunder.com/devres/live ... ext002.htm
http://www.sonsothunder.com/devres/live ... ext003.htm

Re: How to prevent Windows from Screensaver while program running

Posted: Fri Apr 19, 2019 1:39 pm
by AxWald
Hi,

a rather crude way is demonstrated in the attached stack. Idea is to send a keystroke periodically that prevents the screen saver from kicking in. NUMLOCK came to mind - twice in quick succession.

Actually this idea came from VBS forums. Anyway, I couldn't get it running via the usual

Code: Select all

do myVBS as "VBScript"
For whatever reason. The VBS is rather simple & runs fine when invoked in any other way:

Code: Select all

Set myShell = WScript.CreateObject("WScript.Shell")
myShell.SendKeys ("{NUMLOCK}")
WScript.Sleep 10
myShell.SendKeys ("{NUMLOCK}")
As you see, it invokes NUMLOCK twice, with 10ms pause.
To make it work in LC I had to make an .exe from it. Find it attached as "HitNum10.exe".

Now you might be a smart coder & ever reluctant to run .exes from shady sources - for you it's attached as a simple .vbs text file. And if you want to compile it yourself, I have added a link to the tool I used to compile. The evaluation version works well.

Remark: Both VBS & stack are "quick & dirty". Use at your own risk! (It didn't eat my machine, though.)

Have fun!

Re: How to prevent Windows from Screensaver while program running

Posted: Thu Sep 23, 2021 6:08 pm
by studawg66
AxWald,
Dredging up an old thread in desperation. Haha.
I tried your approach and it works, but running that external executable seems to be a blocking operation, because my clock readout freezes for a second or two until it finishes executing. Since my application is a precision clock, that is a no go :) Is there a way to make such a script execution non-blocking? I found a couple of threads about this but didn't find a solution.
I've tried numerous other tricks and asked some questions regarding those, but not getting any responses, so thinking it is just too difficult for LiveCode to accomplish. My Python program executes it in one line and doesn't require strange keyboard hacks to run every few seconds, so it is frustrating that I can't execute the same thing in this environment.