Page 1 of 1
Check if screen saver is active (Windows)
Posted: Sun Jan 31, 2021 12:50 pm
by Michael Vogel
I wrote a 'smart home' program which shows a map with the light state of dozens of bulbs. Checking all states means a short peak of network traffic, so this is regularly done only when there is user interaction. Otherwise I will do only a check every minute, but I 'd like to slow done this to lower rates, when the screen saver is on (and do a full update when the screen saver will stop)...
Don't think there's a windows message that a screen saving will be activated or stopped...
...but is there any other possibility to get some information about that?
Re: Check if screen saver is active (Windows)
Posted: Sun Jan 31, 2021 1:14 pm
by PureLust
Hi Michael,
I found a blog with some Infos about how to check if a Screensaver is active :
https://devblogs.microsoft.com/scriptin ... %20running.
Zitat: "If we want to know whether or not the screen saver is running all we have to do is check and see if there are any processes running that have an executable name ending inĀ .scr. If there are, that probably means the screen saver is running."
Gesendet von meinem LYA-L29 mit Tapatalk
Re: Check if screen saver is active (Windows)
Posted: Sun Jan 31, 2021 1:14 pm
by Mijikai
U can check if a screensaver is running.
Code: Select all
Debug SystemParametersInfo_(#SPI_GETSCREENSAVERRUNNING,#Null,#Null,#Null)
Mby also useful:
Code: Select all
Procedure.i IdleTimeInMilliseconds()
Protected info.LASTINPUTINFO
info\cbSize = SizeOf(LASTINPUTINFO)
GetLastInputInfo_(@info)
ProcedureReturn GetTickCount_() - info\dwTime
EndProcedure
Re: Check if screen saver is active (Windows)
Posted: Sun Jan 31, 2021 2:52 pm
by RASHAD
Hi MV
Compile the next snippet as exe
Run the exe
Adapt it in your application
Code: Select all
Prototype SplashMessageSetup(hWnd,lpText$,lpCaption$,uType, wLanguageID.w,dwMilliseconds)
Procedure SplashMessage(title$,text$,ms=1000,icon=#MB_ICONINFORMATION)
lib=OpenLibrary(#PB_Any,"user32.dll")
If lib
SplashMessageSetup.SplashMessageSetup=GetFunction(lib, "MessageBoxTimeoutW")
SplashMessageSetup(GetForegroundWindow_(),text$,title$, #MB_SETFOREGROUND|#MB_TOPMOST|#MB_TASKMODAL|icon,0, ms)
CloseLibrary(lib)
EndIf
EndProcedure
Procedure WndProc(hwnd, uMsg, wParam, lParam)
result = #PB_ProcessPureBasicEvents
Select uMsg
Case #WM_SYSCOMMAND
Select wParam
Case #SC_SCREENSAVE
SplashMessage("Info"," Screen Saver is Running",2000)
EndSelect
EndSelect
ProcedureReturn result
EndProcedure
flags = #PB_Window_SystemMenu| #PB_Window_MaximizeGadget| #PB_Window_MinimizeGadget| #PB_Window_ScreenCentered | #PB_Window_SizeGadget
OpenWindow(0,0,0,400,300,"Test",Flags)
StickyWindow(0,1)
SetWindowCallback(@WndProc())
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Quit = 1
EndSelect
Until Quit = 1
Re: Check if screen saver is active (Windows)
Posted: Sun Jan 31, 2021 6:00 pm
by Michael Vogel
Thanks, will check all your hints, there's just one point (which I haven't mentioned in the post above)...
...some PC's don't start an explicit screen saver program, but do show a black screen after a while.
Anyhow I have checked SystemParametersInfo_(#SPI_GETSCREENSAVERRUNNING,0,0,0) some days before, but this never returned a value different to 0
Update - seems that my initial question wasn't very precise, I've checked some PC's now and found most of them haven't enabled a screen saver but have configured a "monitor off" mode in the energy options. So the trick for IdleTimeInMilliseconds() could be the best now...
Re: Check if screen saver is active (Windows)
Posted: Sun Jan 31, 2021 6:32 pm
by PureLust
Michael wrote: ...some PC's don't start an explicit screen saver program, but do show a black screen after a while.
Sounds like Monitor Powersaving mode.
I'm not sure, but I think I've posted a function to check for Powersaving modes a while ago.
I'll have a look if I can find it.
Gesendet von meinem LYA-L29 mit Tapatalk
Re: Check if screen saver is active (Windows)
Posted: Sun Jan 31, 2021 6:58 pm
by Michael Vogel
'Powersave' sounds good as well...
..actually I'll try to implement something like to following - when going to active, the refresh rate will be high, in idle mode no refreshing will be done then:
Code: Select all
Procedure.i IdleOrActive()
Protected info.LASTINPUTINFO
Protected n,t
Shared ioa_last
Shared ioa_trend
info\cbSize = SizeOf(LASTINPUTINFO)
GetLastInputInfo_(@info)
n=GetTickCount_()-info\dwTime
t=ioa_trend
ioa_trend=Bool(n<=ioa_last)
ioa_last=n
ProcedureReturn Bool(t<>ioa_trend)
EndProcedure
For i=1 To 1000
If IdleOrActive()
Debug StringField("IDLE.ACTIVE",ioa_trend+1,".")+", "+Str(ioa_last)
Else
Debug "."
EndIf
Delay(1000)
Next i
Re: Check if screen saver is active (Windows)
Posted: Sun Jan 31, 2021 9:36 pm
by Lunasole
Yes, using lastinput info should be a best way to control user interaction.
I'm having slightly different code running at background -- it automatically enables screensaver with a short timeout when mouse pointer is parked at the top of the screen (Y <= 6), and disables else.