mucitbey Posted November 12, 2019 Share Posted November 12, 2019 Hi, #NoTrayIcon #Include <Timers.au3> HotKeySet("{ESC}", "On_Exit") While 1 If _Timer_GetIdleTime() > 6300000 Then Run("Closer.exe") While _Timer_GetIdleTime() > 500 Sleep(10) WEnd ProcessClose("Closer.exe") EndIf Sleep(10) $timer = TimerInit() Do Until TimerDiff($timer) >= 600000 $iFileExist = FileExists("\\ANKSERVER\ank\Tools\csb.ini") If $iFileExist Then Run("C:\RedStone\Tools\Message.exe") Else EndIf WEnd Func On_Exit() Exit EndFunc How can I reduce the CPU usage of this code, is there any way I can help with this? Thank you in advance for your help. The code I tried with AddlibRegister didn't work, or I couldn't. Link to comment Share on other sites More sharing options...
pixelsearch Posted November 12, 2019 Share Posted November 12, 2019 (edited) Hi mucitbey The solution is to move the 2nd Sleep(10) between Do and Until, which will reduce drastically the CPU usage : #NoTrayIcon #Include <Timers.au3> HotKeySet("{ESC}", "On_Exit") While 1 If _Timer_GetIdleTime() > 6300000 Then Run("Closer.exe") While _Timer_GetIdleTime() > 500 Sleep(10) WEnd ProcessClose("Closer.exe") EndIf ; Sleep(10) $timer = TimerInit() Do Sleep(10) ; <======= Until TimerDiff($timer) >= 600000 $iFileExist = FileExists("\\ANKSERVER\ank\Tools\csb.ini") If $iFileExist Then Run("C:\RedStone\Tools\Message.exe") EndIf WEnd Func On_Exit() Exit EndFunc Edited November 12, 2019 by pixelsearch mucitbey 1 Link to comment Share on other sites More sharing options...
mucitbey Posted November 12, 2019 Author Share Posted November 12, 2019 (edited) pixelsearch,Thanks again for your help and support. Result; Before CPU Usage %14,7 After CPU Usage %0 Edited November 12, 2019 by mucitbey Link to comment Share on other sites More sharing options...
pixelsearch Posted November 12, 2019 Share Posted November 12, 2019 Link to comment Share on other sites More sharing options...
mucitbey Posted November 12, 2019 Author Share Posted November 12, 2019 How can we do the same? expandcollapse popup#NoTrayIcon #include <MsgBoxConstants.au3> #include <TrayConstants.au3> #include <Misc.au3> _Singleton(@ScriptName, 0) HotKeySet("{ESC}", "On_Exit") $lastPos = MouseGetPos() $lastMove = TimerInit() Opt("TrayMenuMode", 3) _ST() Func _ST() Flash() TraySetState($TRAY_ICONSTATE_SHOW) While 1 $curPos = MouseGetPos() If($lastPos[0] == $curPos[0] And $lastPos[1] == $curPos[1]) Then If( TimerDiff($lastMove) > 250000) Then MouseMove(Random(1, @DesktopWidth, 1), Random(1, @DesktopHeight, 1)) EndIf Else $lastPos = $curPos $lastMove = TimerInit() EndIf WEnd EndFunc Func Flash() TraySetState($TRAY_ICONSTATE_FLASH) Sleep(1000) EndFunc Func On_Exit() Exit EndFunc Link to comment Share on other sites More sharing options...
water Posted November 12, 2019 Share Posted November 12, 2019 What is this script supposed to do? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Nine Posted November 12, 2019 Share Posted November 12, 2019 Like previously, just put a small Sleep (100) inside the loop. While we are there, you do not need to put () around a If. It is not necessary. Also == is for comparing case sensitive strings, not numbers. Use = instead. So your code should look like this : expandcollapse popup#NoTrayIcon #include <MsgBoxConstants.au3> #include <TrayConstants.au3> #include <Misc.au3> _Singleton(@ScriptName, 0) HotKeySet("{ESC}", "On_Exit") $lastPos = MouseGetPos() $lastMove = TimerInit() Opt("TrayMenuMode", 3) _ST() Func _ST() Flash() TraySetState($TRAY_ICONSTATE_SHOW) While 1 Sleep (100) $curPos = MouseGetPos() If $lastPos[0] = $curPos[0] And $lastPos[1] = $curPos[1] Then If TimerDiff($lastMove) > 250000 Then MouseMove(Random(1, @DesktopWidth, 1), Random(1, @DesktopHeight, 1)) Else $lastPos = $curPos $lastMove = TimerInit() EndIf WEnd EndFunc Func Flash() TraySetState($TRAY_ICONSTATE_FLASH) Sleep(1000) EndFunc Func On_Exit() Exit EndFunc mucitbey 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
mucitbey Posted November 12, 2019 Author Share Posted November 12, 2019 2 hours ago, water said: What is this script supposed to do? If the mouse does not move for 5 minutes, move the mouse to prevent the system from shutting down. Link to comment Share on other sites More sharing options...
mucitbey Posted November 12, 2019 Author Share Posted November 12, 2019 1 hour ago, Nine said: Like previously, just put a small Sleep (100) inside the loop. While we are there, you do not need to put () around a If. It is not necessary. Also == is for comparing case sensitive strings, not numbers. Use = instead. So your code should look like this : expandcollapse popup#NoTrayIcon #include <MsgBoxConstants.au3> #include <TrayConstants.au3> #include <Misc.au3> _Singleton(@ScriptName, 0) HotKeySet("{ESC}", "On_Exit") $lastPos = MouseGetPos() $lastMove = TimerInit() Opt("TrayMenuMode", 3) _ST() Func _ST() Flash() TraySetState($TRAY_ICONSTATE_SHOW) While 1 Sleep (100) $curPos = MouseGetPos() If $lastPos[0] = $curPos[0] And $lastPos[1] = $curPos[1] Then If TimerDiff($lastMove) > 250000 Then MouseMove(Random(1, @DesktopWidth, 1), Random(1, @DesktopHeight, 1)) Else $lastPos = $curPos $lastMove = TimerInit() EndIf WEnd EndFunc Func Flash() TraySetState($TRAY_ICONSTATE_FLASH) Sleep(1000) EndFunc Func On_Exit() Exit EndFunc Thanks Nine,Once again excellent approach, excellent result. Thanks also for your information and referrals. Link to comment Share on other sites More sharing options...
BigDaddyO Posted November 12, 2019 Share Posted November 12, 2019 5 hours ago, mucitbey said: If the mouse does not move for 5 minutes, move the mouse to prevent the system from shutting down. You may want to look into this if all you want to do is keep a system awake. There are lots of deep discussions in there on how to keep a system active while stuff is running in the background. mucitbey 1 Link to comment Share on other sites More sharing options...
mucitbey Posted November 13, 2019 Author Share Posted November 13, 2019 9 hours ago, BigDaddyO said: You may want to look into this if all you want to do is keep a system awake. There are lots of deep discussions in there on how to keep a system active while stuff is running in the background. Thanks BigDaddy,I've been using this gui for 6 months without problems, the only problem was CPU usage, which was solved by @pixelsearch and @Nine.It's good to have @Autoit and valuable forum members. Link to comment Share on other sites More sharing options...
mucitbey Posted January 2, 2020 Author Share Posted January 2, 2020 (edited) Hi, I want to change the wait value ($ stay) on this code according to time. I tried to do it with If, but I couldn't solve the problem, anybody have any ideas? Thank you. #NoTrayIcon #Include <Timers.au3> HotKeySet("{ESC}", "On_Exit") While 1 If @HOUR < 16 Then $stay = 10000 ; 10 minute (600000) (I shortened the time to be able to test.) Else $stay = 60000 ; 90 minute (5400000)(I shortened the time to be able to test.) EndIf If _Timer_GetIdleTime() > $stay Then Run("Close.exe") While _Timer_GetIdleTime() > 500 Sleep (10) WEnd ProcessClose("Close.exe") EndIf $timer = TimerInit() Do Sleep(10) Until TimerDiff($timer) >= 600000 $ifEx = FileExists("\\ANKSERVER\ank\Tools\csb.ini") If $ifEx Then Run("C:\RedStone\Tools\Message.exe") WEnd Func On_Exit() Exit EndFunc What I'm trying to do is; I want to set the waiting time to 90 minutes until 16:59 and 10 minutes after 17:00 Edited January 2, 2020 by mucitbey Link to comment Share on other sites More sharing options...
Nine Posted January 2, 2020 Share Posted January 2, 2020 Few problems here : 1- @HOUR returns a string (see help file). You should convert it to number with Int() before. 2- Your do...until has a value larger than the $stay, no wonder it doesn't work for your test. 3- If you want to check for 16:59, you should use <= not just < “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
mucitbey Posted January 2, 2020 Author Share Posted January 2, 2020 40 minutes ago, Nine said: Few problems here : 1- @HOUR returns a string (see help file). You should convert it to number with Int() before. 2- Your do...until has a value larger than the $stay, no wonder it doesn't work for your test. 3- If you want to check for 16:59, you should use <= not just < Understood thanks. 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