How to prevent Windows from Screensaver while program running

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
studawg66
Posts: 25
Joined: Wed Jun 17, 2015 9:40 pm

How to prevent Windows from Screensaver while program running

Post by studawg66 » Thu Apr 18, 2019 7:54 pm

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?

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: How to prevent Windows from Screensaver while program running

Post by bogs » Thu Apr 18, 2019 9:13 pm

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.
Image

studawg66
Posts: 25
Joined: Wed Jun 17, 2015 9:40 pm

Re: How to prevent Windows from Screensaver while program running

Post by studawg66 » Thu Apr 18, 2019 9:48 pm

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?

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: How to prevent Windows from Screensaver while program running

Post by bogs » Thu Apr 18, 2019 10:08 pm

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
Image

AxWald
Posts: 578
Joined: Thu Mar 06, 2014 2:57 pm

Re: How to prevent Windows from Screensaver while program running

Post by AxWald » Fri Apr 19, 2019 1:39 pm

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!
Attachments
NoSleep.zip
A rather crude demo that prevents the screen from sleeping
(124.96 KiB) Downloaded 267 times
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!

studawg66
Posts: 25
Joined: Wed Jun 17, 2015 9:40 pm

Re: How to prevent Windows from Screensaver while program running

Post by studawg66 » Thu Sep 23, 2021 6:08 pm

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.

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”