Jump to content

Timer to Prevent Screensaver


Recommended Posts

I'm looking for a function that stands alone (not in a loop, etc.) and when a preset time elapses it moves the mouse to prevent the screensaver from coming on.

I don't think I can get TimerInit and TimerDiff to work but I am trying.

Basically I'm looking for something like this:

Start a Timer

When Timer elapsed time = 300 seconds call TimerElapsed() ;after 5 minutes call the function and repeat if necessary.

;

; Lots of code independent of Timer

.

.

.

Func TimerElapsed

MouseMove (X.Y)

EndFunc

Edited by rwright142
Link to comment
Share on other sites

rwright142,

Building on FireFox's example using an adlib.

;
;  adlib to run every 5 mins and check user idle time
;

#include <WinAPIEx.au3>
#include <windowsconstants.au3>

local $adlib_010_time = 1000*60*5

adlibregister('_adlib_010',$adlib_010_time)

while 1
    sleep(86400000) ; loop once a day - arbitrary value just to keep script alive without burning cycles
WEnd

func _adlib_010()

    ; I'm flashing a red screen for 1/4 second just to verify that it is working...you probably want your mouse move or keypress here

    if _winapi_getidletime() > $adlib_010_time then
        guicreate('',@DesktopWidth,@DesktopHeight,0,0,$ws_popup)
        guisetbkcolor(0xff0000)
        guisetstate()
        sleep(250)
        guidelete()
    endif

endfunc

Why don't you use Windows to just disable/change the screensaver if it is a problem?

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

I created something similar a week ago. I went with the following...

_Timer_SetTimer
_Timer_KillTimer
_Timer_GetIdleTime
MouseGetPos
MouseMove

FireFox,

You know I use WinAPIEx alot, but the other day I realised _WinAPI_GetIdleTime was already in the Timers UDF.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Thanks all, I will research the _Timer functions.

In the program I am writing has a sleep() command and I could see where the sleep time may be longer than a user's screensaver delay. That is why I am looking for some kind of a trigger that kicks in at a predetermined time.

@Kylomas, I don't want to make any changes to the user's personal settings like the screensaver.

Edited by rwright142
Link to comment
Share on other sites

rwright142,

I see, missed the part where you said that you cannot change the screen saver, for whatever reason. If the user can change the screen saver time you may be able to get the screen saver timeout value from the registry. Using that you can set your keep-alive program to act just before that interval expiration. If the user cannot change their screen saver timeout value then there must be some common distribution value (or MS default) that you can key off of.

That is why I am looking for some kind of a trigger that kicks in at a predetermined time.

The code that I posted does this without burning user mode cpu cycles. Unless there's more to the story, I don't see how FireFox's solution with my tweak to elimiate timers does not fit your requirement.

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

Thanks for all the replies, I will see what I can come up with. Where can I find WinAPIEx.au3 that is included? Also, does the Sleep command prevent anything else from running?

Sorry if this is a newby question, but hey, I'm a newby LOL

Edited by rwright142
Link to comment
Share on other sites

rwright142,

NP, we all start somewhere. You can download the WINAPIEx.au3 from the forum, just do a search for it.

The sleep command will stop your script from doing anything else, except of course the adlib. The posted code is an example. In real life you can have a gui, file download, whatever running and the adlib will execute at the interval specified along side of whatever what you are doing in the main code. One warning, don't use any blocking functions, MSGBOX primarily, in the adlib as that will block your script.

Hope this helps!

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

rwright142,

Here is a simple example of adlib usage. The script let's the user type into the edit box and saves the contents of the edit box to a file whenever the adlib runs. The user also has the option to toggle the adlib off and on.

This script will create a file called "edit_aut_save.txt" in whatever dir you run it from.

;
; adlib example
;

#include <StaticConstants.au3>
#include <GUIConstantsEx.au3>
#include <date.au3>

#AutoIt3Wrapper_Add_Constants=n

local $gui010   =   guicreate('ADLIB Example Script')
local $aSize    =   wingetclientsize($gui010)
local $edt010   =   guictrlcreateedit('',10,10,$asize[0]-20,$asize[1]-80)
local $btn010   =   guictrlcreatebutton('Stop AutoSave',10,$asize[1]-60,$asize[0]-20)
                    guictrlsetcolor(-1,0x0000ff)
                    guictrlsetfont(-1,10,800)
local $status   =   guictrlcreatelabel('',10,$asize[1]-30,$asize[0]-20,20,$ss_sunken)
                    guictrlsetfont(-1,8.5,800,-1,'Lucinda Console')
                    guictrlsetcolor(-1,0xaa0000)
                    guisetstate()

adlibregister('AutoSave',5000)

While 1
    switch GUIGetMsg()
        case $GUI_EVENT_CLOSE
            Exit
        case $btn010
            if guictrlread($btn010) = 'Stop AutoSave' then                  ; check button text
                adlibunregister('AutoSave')                                 ; stop adlib
                guictrlsetdata($btn010,'Start AutoSave')                    ; set button text to 'start'
                guictrlsetdata($status,'AutoSave Stopped at ' & _now())     ; report status
                guictrlsetstate($edt010,$gui_focus)                         ; return focus to edit control
            else
                adlibregister('AutoSave',3000)                              ; button controltext was 'start' so register adlib
                guictrlsetdata($btn010,'Stop AutoSave')                     ; toggle button control text
                guictrlsetdata($status,'AutoSave Started at ' & _now())     ; report status
                guictrlsetstate($edt010,$gui_focus)                         ; return focus to edit control
            endif
    EndSwitch
wend

func Autosave()

    local $fln = @scriptdir & '\edit_auto_save.txt'
    local $hfl = fileopen($fln,2)
    if $hfl = -1 then
        guictrlsetdata($status,'AutoSave File Failed to Open')
        Return
    Else
        guictrlsetdata($status,'Last AutoSave at ' & _now())
    EndIf
    filewrite($hfl,guictrlread($edt010))
    fileclose($hfl)
    $hfl = 0

endfunc

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

Thanks again Kylomas. I searched for WINAPIEx.au3 in "downloads" which I thought would have been the obvious place but didn't find it there but I'll keep looking.

OOps... I think I broke something LOL. I tried searching in the forums for the file and I received this message:

---------------------------------------------------

SQL Error

An error occured with the SQL server:

This is not a problem with IP.Board but rather with your SQL server. Please contact your host and copy the message shown above.

---------------------------------------------------

Hope everyone has a safe and Happy New Year!

Edited by rwright142
Link to comment
Share on other sites

You could just disable and renable after you have finished

RegWrite("HKEY_CURRENT_USER\Control Panel\Desktop", "ScreenSaveActive", "REG_SZ", "0")    ; Disable Screensaver

That disables but you may need to refresh explorer.exe after

RunWait(@ComSpec & " /c " & "taskkill /f /im explorer.exe", "", @SW_HIDE) ; refresh desktop
     RunWait(@ComSpec & " /c " & "start " & @WindowsDir & "\explorer.exe", "", @SW_HIDE) ; refresh desktop
Edited by Chimaera
Link to comment
Share on other sites

rwright142,

You can download Yashied's WinapiEx.au3

You need whatever auth is required to alter the registry, probably admin (possibly by running your script elevated with #RequireAdmin, maybe one of the sys admins can advise). I found several related topics using a google search for "screen saver registry".

kylomas

edit: additional info - this is from the help file for "regwrite'

It is possible to access remote registries by using a keyname in the form "computernamekeyname". To use this feature you must have the correct access rights on NT/2000/XP/2003.

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

I use the script below to avoid the screen saver, it move the mouse every 60 seconds.

#Include <WinAPI.au3>
#include <Constants.au3>

$start = TimerInit()
While 1
    If TimerDiff($start) > 60000 Then
        _WinAPI_Mouse_Event($MOUSEEVENTF_MOVE)
        $start = TimerInit()
    EndIf
WEnd
AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Link to comment
Share on other sites

Danny35d,

You might want to put a "sleep" in that loop. When run on my Win 7 64 bit processor it eats appx. 25% of the CPU.

Oddly enough, when I run it uder SCiTE it does NOT chew up the CPU.

kylomas

edit: Looking at process explorer cross-eyed, code eats CPU regardless of how it's started

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

  • 6 months later...

Dschingis,

You may want to add a sleep inside the tight loop. Plus, it might be an interesting chance for you to try other methods, as there are plenty of other ways to achieve this,

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...