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: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

Post Reply
studawg66
Posts: 18
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: 3785
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: 18
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: 3785
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: 368
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 19 times
Livecode programming until the cat hits the fan ...

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”