Page 1 of 1
No Stop No Sleep [Windows]
Posted: Wed Sep 14, 2016 9:40 pm
by RASHAD
Tested with Windows XP,7,8,10 x64
Code: Select all
;LeftClick to Quit
Procedure NoSleep(Para)
fx.f = $FFFF / GetSystemMetrics_(#SM_CXSCREEN)
fy.f = $FFFF / GetSystemMetrics_(#SM_CYSCREEN)
In.INPUT
In\type = #INPUT_MOUSE
In\mi\dwFlags = #MOUSEEVENTF_MOVE|#MOUSEEVENTF_ABSOLUTE
Repeat
Delay(3000)
GetCursorPos_(cur.POINT)
In\mi\dx = (cur\x+1) * fx
In\mi\dy = (cur\y+1) * fy
SendInput_(1,@In,SizeOf(In))
SendInput_(1,@In,SizeOf(In))
ForEver
EndProcedure
IconName$ = #PB_Compiler_Home + "examples/sources/Data/CdPlayer.ico"
OpenWindow(0,0,0,0,0,"",#PB_Window_BorderLess)
AddSysTrayIcon(0, WindowID(0), LoadImage(0, IconName$))
Thread = CreateThread(@NoSleep(),30)
Repeat
Select WaitWindowEvent(1)
Case #PB_Event_SysTray
Select EventType()
Case #PB_EventType_LeftClick
Quit = 1
EndSelect
EndSelect
Until Quit = 1
Re: No Stop No Sleep [Windows]
Posted: Wed Sep 14, 2016 11:00 pm
by freak
There is an API function specifically for this purpose, so you don't need to simulate fake input:
https://msdn.microsoft.com/de-de/librar ... 73208.aspx
Re: No Stop No Sleep [Windows]
Posted: Wed Sep 14, 2016 11:02 pm
by RSBasic
Re: No Stop No Sleep [Windows]
Posted: Wed Sep 14, 2016 11:09 pm
by RASHAD
freak & RSbasic
Sorry ,I know about that but it did not work
I am doing a MMedia player and that did not work with XP Screen saver SP2 to be exact so I got to see some other way to solve my problem
Beside no harm to have another way
Sorry
Re: No Stop No Sleep [Windows]
Posted: Fri Sep 30, 2016 7:48 am
by Roger Hågensen
If it didn't work you did it wrong.
As per
https://msdn.microsoft.com/en-us/librar ... s.85).aspx
"This function does not stop the screen saver from executing."
"to keep the display or system in the working state, the thread must call SetThreadExecutionState periodically."
ES_CONTINUOUS and ES_DISPLAY_REQUIRED should be the only flags you need.
Unless i misread it you should use SetThreadExecutionState(ES_CONTINUOUS|ES_DISPLAY_REQUIRED)
and when done playing you use SetThreadExecutionState(ES_CONTINUOUS) to clear the display flag, the documentation does not say what passing 0 does so do not rely on that.
Alternatively you can use then periodically use SetThreadExecutionState(ES_DISPLAY_REQUIRED) periodically, try once a minute first (I think that is the minimum screen saver setting).
Also note that your code could be a issue at least for people like me that watch video and do other stuff at the same time, I'd never use a player that hogs the mouse pointer preveting me from doing anything else.
And before you say "this will only be used in fullscreen", well what about those with multiple monitors? I often have video fullscreen on my main monitor but other stuff on my secondary monitor.
__________________________________________________
URL tags added
30.09.2016
RSBasic
Re: No Stop No Sleep [Windows]
Posted: Fri Sep 30, 2016 6:05 pm
by RASHAD
Hi
Should I believe you or MSDN and myself
MSDN says(Read your MSDN link carefully and you did it all ready)
This function does not stop the screen saver from executing.
If it will then MSDN should say use it periodically even if you are using ES_CONTINUOUS
Beside using it periodically just in case
Calling SetThreadExecutionState without ES_CONTINUOUS simply resets the idle timer; to keep the display or system in the working state, the thread must call SetThreadExecutionState periodically.
Did not work with XP SP2 by testing all options (Sorry)
I am not the only one who did that Symantic and Nirsoft and others did it before
I made it available in PB instead of running external exe
Seems everything running smoothly the Player and any application at the same time
Reading and talking can not take over exercising and testing
Re: No Stop No Sleep [Windows]
Posted: Sat Oct 01, 2016 10:19 pm
by Michael Vogel
I am using the following
program for windows, which helps to keep my notebook running overnight if needed.
You can use a combination of characters as a start parameter to change the behaviour of the tool, a short information about this will be displayed when using the parameter '?'. While the program is active, you can also use the keyboard to toggle some options, like 'd' to keep the display active or not.
Re: No Stop No Sleep [Windows]
Posted: Sat Oct 01, 2016 10:52 pm
by RASHAD
Hi MV
I can not depend on external tool
The code embedded into the MMplayer code
It runs when you run your code so if your application crashed for some reason your system still have its defaults no problem
This technique is foolproof for all Windows versions(By testing) and so simple
and
no side effects
Some of other techniques if you want to read some more
http://www.codeproject.com/Tips/125769/ ... creensaver
Code: Select all
SystemParametersInfo_(#SPI_SETSCREENSAVEACTIVE, 1, 0, #SPIF_SENDWININICHANGE)
;****************************************************************
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
Case WM_SYSCOMMAND:
{
switch (wParam)
{
Case SC_SCREENSAVE:
Return 0;
Case SC_MONITORPOWER:
Return 0;
}
Break;
}
Case WM_CLOSE:
{
PostQuitMessage(0);
Return 0;
}
}
Return DefWindowProc(hWnd,uMsg,wParam,lParam);
;****************************************************************
[ SMPlayer Support Forum
Index: src/screensaver.cpp
==================================================
--- src/screensaver.cpp (revision 5760)
+++ src/screensaver.cpp (working copy)
@@ -85,7 +85,8 @@
SystemParametersInfo(SPI_SETPOWEROFFTIMEOUT, poweroff, NULL, 0);
}
SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, screensaver, NULL, 0);
-
+ SetThreadExecutionState(ES_CONTINUOUS);
+
qDebug("WinScreenSaver::restoreState: lowpower: %d, poweroff: %d, screensaver: %d", lowpower, poweroff, screensaver);
#else
If (SSCore_TempEnable) {
@@ -117,6 +118,7 @@
SystemParametersInfo(SPI_SETPOWEROFFTIMEOUT, 0, NULL, 0);
}
SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, 0, NULL, 0);
+ SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED);
#else
If (SSCore_TempDisable) {
SSCore_TempDisable();
Index: src/screensaver.h
==================================================
--- src/screensaver.h (revision 5760)
+++ src/screensaver.h (working copy)
@@ -23,6 +23,8 @@
#ifdef Q_OS_OS2
#include <QLibrary>
+#else
+#define _WIN32_WINNT 0x0501
#endif
class WinScreenSaver
;***************************************************************
To disable Or enable screen saver using registry key
Set the value of the registry value ScreenSaveActive To 0. From command line you can run the below command For doing this.
Reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v ScreenSaveActive /t REG_SZ /d 0 /f
To enable screen saver:
Reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v ScreenSaveActive /t REG_SZ /d 1 /f
in Case of a ctrl+alt+del Or a crash the screensaver won't go back to normal
SMPlayer one of the best mmedia players at the moment
I just picked Mouse jiggler to be my favorite