rwright142 Posted December 31, 2012 Share Posted December 31, 2012 (edited) 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 December 31, 2012 by rwright142 Link to comment Share on other sites More sharing options...
FireFox Posted December 31, 2012 Share Posted December 31, 2012 Hi, You will need a loop, because your code will be repeated each time the user is idle. #include <WinAPIEx.au3> While 1 If _WinAPI_GetIdleTime() >= 300 * 1000 Then ;300 sec TimerElapsed() EndIf Sleep(1000) WEnd You can also set a callback timer with the function _Timer_SetTimer Br, FireFox. Link to comment Share on other sites More sharing options...
GordonFreeman Posted December 31, 2012 Share Posted December 31, 2012 $SECONDS = 300 $SECONDS = $SECONDS * 1000 Func TimerElapsed() For $i = 1 to 2 Sleep($SECONDS) MouseMove (Random(1, @DesktopWidth,1), Random(1, @DesktopHeight,1)) $i = $i - 1 Next EndFunc TimerElapsed() Always need a loop Frabjous Installation Link to comment Share on other sites More sharing options...
kylomas Posted December 31, 2012 Share Posted December 31, 2012 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 More sharing options...
guinness Posted December 31, 2012 Share Posted December 31, 2012 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. FireFox 1 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 parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
rwright142 Posted December 31, 2012 Author Share Posted December 31, 2012 (edited) 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 December 31, 2012 by rwright142 Link to comment Share on other sites More sharing options...
kylomas Posted December 31, 2012 Share Posted December 31, 2012 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 More sharing options...
rwright142 Posted December 31, 2012 Author Share Posted December 31, 2012 (edited) 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 December 31, 2012 by rwright142 Link to comment Share on other sites More sharing options...
kylomas Posted January 1, 2013 Share Posted January 1, 2013 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 More sharing options...
kylomas Posted January 1, 2013 Share Posted January 1, 2013 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. expandcollapse popup; ; 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 More sharing options...
rwright142 Posted January 1, 2013 Author Share Posted January 1, 2013 (edited) 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 ErrorAn 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 January 1, 2013 by rwright142 Link to comment Share on other sites More sharing options...
Chimaera Posted January 1, 2013 Share Posted January 1, 2013 (edited) 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 January 1, 2013 by Chimaera If Ive just helped you ... miracles do happen. Chimaera CopyRobo() * Hidden Admin Account Enabler * Software Location From Registry * Find Display Resolution * _ChangeServices() Link to comment Share on other sites More sharing options...
rwright142 Posted January 1, 2013 Author Share Posted January 1, 2013 (edited) @Chimaera, Interesting idea, but am I correct in thinking this won't work if the user is NOT a local administrator? Edited January 1, 2013 by rwright142 Link to comment Share on other sites More sharing options...
kylomas Posted January 1, 2013 Share Posted January 1, 2013 (edited) 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".kylomasedit: 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 January 1, 2013 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 More sharing options...
Danny35d Posted January 1, 2013 Share Posted January 1, 2013 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 Dschingis 1 AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line Link to comment Share on other sites More sharing options...
kylomas Posted January 1, 2013 Share Posted January 1, 2013 (edited) 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.kylomasedit: Looking at process explorer cross-eyed, code eats CPU regardless of how it's started Edited January 1, 2013 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 More sharing options...
Dschingis Posted July 6, 2013 Share Posted July 6, 2013 Nice idea, Danny35D. I'll try this. Link to comment Share on other sites More sharing options...
guinness Posted July 6, 2013 Share Posted July 6, 2013 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 parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now