Chantaro Posted August 25, 2021 Share Posted August 25, 2021 Hi, I'm trying to run a script that handles our document bots from stopping at work. I want to add an extra action (mouseclick) and to make it send me a notification if after said action the idletimer goes up again: expandcollapse popup#Region Init #include "ALK-Bots.au3" #include "Access_UDF.au3" #include <Array.au3> #include <MsgBoxConstants.au3> #include <File.au3> #include <Date.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <DateTimeConstants.au3> #include <Timers.au3> AutoItSetOption("WinTitleMatchMode",2) ; Break für Abbruch HotKeySet("{BREAK}","ExitScript") HotKeySet("{PAUSE}","ExitScript") Func ExitScript() If MsgBox (4, "Break" ,"Break gedrückt. Programm stoppen?") = 6 Then Exit EndFunc #EndRegion Init While 1 ConsoleWrite(_Timer_GetIdleTime() & @CRLF) If _Timer_GetIdleTime() > 10000 Then ;5 minutes 300000 GetWindow() If Ubound($ArrayError) < 2 Then ;If no window found MouseClick("left",1168, 727) Sleep(500) MouseClick("left",267, 574,2) If _Timer_GetIdleTime() > 6000 Then Notification() EndIf Else If $ArrayError[1][0] = ("ASAL-ALK Hauptmenu nicht gefunden") Then WinActivate("Sitzung") WinWaitActive("Sitzung") Send("{F12}") Sleep(1000) Send("15") Sleep(1000) Send("{Enter}") Sleep(1000) WinActivate("ASAL-ALK Hauptmenu nicht gefunden") WinWaitActive("ASAL-ALK Hauptmenu nicht gefunden") Send("{RIGHT}") Send("{Enter}") EndIf EndIf EndIf WEnd Func GetWindow() Global $Array = WinList("GUI") Global $ArrayError = WinList("ASAL-ALK Hauptmenu nicht gefunden") EndFunc Func Notification() WinSetState("megumin","",@SW_SHOW) Sleep(2000) WinActivate("megumin") Sleep(2000) Send("{TAB}") Sleep(1000) Send($Array[1][0]) Sleep(1000) Send("{Enter}") Sleep(1000) Send("{!}") Send("highlight 0") Sleep(1000) Send("{Enter}") Sleep(1000) WinSetState("megumin","",@SW_HIDE) MsgBox(0,"Idle","Bot could've stopped") WinSetState("megumin","",@SW_SHOW) Sleep(1000) WinActivate("megumin") Send("{TAB}") Sleep(1000) Send($Array[1][0] & " checked") Sleep(1000) Send("{Enter}") Sleep(1000) WinSetState("megumin","",@SW_HIDE) EndFunc megumin is just an irc bot I use to send me notifications over different computers. But the Problem is that the Idletimer doesn't care about surpassing 6000 after the Mouseclick in the Ubound section. Does AutoIt not allo w to account for multiple Idletimers in a While loop? Thanks Link to comment Share on other sites More sharing options...
pseakins Posted August 25, 2021 Share Posted August 25, 2021 (edited) The Idle time is reset by the mouse click. You can find this out for yourself by writing a simple test instead of waiting for a reply from the forum. #include <Timers.au3> Sleep(500) $iIdleTime = _Timer_GetIdleTime() ConsoleWrite('$iIdleTime = [' & $iIdleTime & ']' & @CRLF) Sleep(500) MouseClick('left') $iIdleTime = _Timer_GetIdleTime() ConsoleWrite('$iIdleTime = [' & $iIdleTime & ']' & @CRLF) As a workaround you can store the idle time value in a variable and then add that value to the 6000 that you are looking for.. Edited August 25, 2021 by pseakins variable naming, workaround Phil Seakins Link to comment Share on other sites More sharing options...
Chantaro Posted August 25, 2021 Author Share Posted August 25, 2021 Yes I'm trying to reset the idletime with the mouseclick but the timer doesn't do that. the ConsoleWrite(_Timer_GetIdleTime() & @CRLF) after While 1 just keeps going after 6000 has been reached, which is how i tested it in the first place Link to comment Share on other sites More sharing options...
Nine Posted August 25, 2021 Share Posted August 25, 2021 I believe there is something wrong on your side. The API is working perfectly fine in a loop : #include <Timers.au3> HotKeySet("{ESC}", _Exit) While Sleep(1000) ConsoleWrite(_Timer_GetIdleTime() & @CRLF) If _Timer_GetIdleTime() > 10000 Then Exit WEnd Func _Exit() Exit EndFunc It resets on mouse move and mouse click (even after 6000)... “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...
Chantaro Posted August 25, 2021 Author Share Posted August 25, 2021 you're both trying _timer_getidletime once in your examples, does it happen if you have the command in a while loop a second time? Link to comment Share on other sites More sharing options...
Nine Posted August 25, 2021 Share Posted August 25, 2021 Just tried it and both reset, which makes sense. It is a global timer, not a timer associated with a unique handle... “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...
Chantaro Posted August 25, 2021 Author Share Posted August 25, 2021 then how come Quote If _Timer_GetIdleTime() > 6000 Then Notification() EndIf is being straight up ignored? Link to comment Share on other sites More sharing options...
Nine Posted August 25, 2021 Share Posted August 25, 2021 Listen. You need to provide a runable snippet of code that shows the issue, not 3 lines out of context. “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...
Chantaro Posted August 25, 2021 Author Share Posted August 25, 2021 then context is in the OP, everything is in there Link to comment Share on other sites More sharing options...
Nine Posted August 25, 2021 Share Posted August 25, 2021 (edited) Well, if you do not want to help yourself, I don't see why I would do it for you. I said runable, the code you provided is not. Until, you give us something to work with, I am afraid you will be on your own. Good Luck. Edited August 25, 2021 by Nine “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...
Chantaro Posted August 25, 2021 Author Share Posted August 25, 2021 runnable script expandcollapse popup#Region Init #include <AutoItConstants.au3> #include "ALK-Bots.au3" #include "Access_UDF.au3" #include <Array.au3> #include <MsgBoxConstants.au3> #include <File.au3> #include <FileConstants.au3> #include <Date.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <DateTimeConstants.au3> #include <Timers.au3> AutoItSetOption("WinTitleMatchMode",2) ; Break für Abbruch HotKeySet("{BREAK}","ExitScript") HotKeySet("{PAUSE}","ExitScript") Func ExitScript() If MsgBox (4, "Break" ,"Break gedrückt. Programm stoppen?") = 6 Then Exit EndFunc #EndRegion Init While 1 ConsoleWrite(_Timer_GetIdleTime() & @CRLF) If _Timer_GetIdleTime() > 12000 Then ;5 minutes 300000 GetWindow() If Ubound($ArrayError) < 2 Then ;If no window found MouseClick("left",1168, 727) Sleep(500) MouseClick("left",267, 574,2) If _Timer_GetIdleTime() > 6000 Then Notification() EndIf EndIf EndIf WEnd Func GetWindow() Global $Array = WinList("GUI") Global $ArrayError = WinList("ASAL-ALK Hauptmenu nicht gefunden") EndFunc Func Notification() WinSetState("megumin","",@SW_SHOW) Sleep(2000) WinActivate("megumin") Sleep(2000) Send("{TAB}") Sleep(1000) Send($Array[1][0]) Sleep(1000) Send("{Enter}") Sleep(1000) Send("{!}") Send("highlight 0") Sleep(1000) Send("{Enter}") Sleep(1000) WinSetState("megumin","",@SW_HIDE) MsgBox(0,"Idle","Bot could've stopped") WinSetState("megumin","",@SW_SHOW) Sleep(1000) WinActivate("megumin") Send("{TAB}") Sleep(1000) Send($Array[1][0] & " checked") Sleep(1000) Send("{Enter}") Sleep(1000) WinSetState("megumin","",@SW_HIDE) EndFunc once again, I can't figure out why it ignores the If _Timer_GetIdleTime() > 6000 Then Notification() part Link to comment Share on other sites More sharing options...
Musashi Posted August 25, 2021 Share Posted August 25, 2021 (edited) 1 hour ago, Chantaro said: once again, I can't figure out why it ignores the If _Timer_GetIdleTime() > 6000 Then Notification() As @pseakins already wrote, the Timer will be reseted by calling MouseClick. The value 6000 is therefore never reached ! Just have a look at the console output of the script: (I made it "runnable" for tests by commenting out lines irrelevant to your problem, and put some ConsoleWrites in there) expandcollapse popup#Region Init #include <AutoItConstants.au3> ;~ #include "ALK-Bots.au3" ;~ #include "Access_UDF.au3" #include <Array.au3> #include <MsgBoxConstants.au3> #include <File.au3> #include <FileConstants.au3> #include <Date.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <DateTimeConstants.au3> #include <Timers.au3> AutoItSetOption("WinTitleMatchMode", 2) ; Break für Abbruch HotKeySet("{BREAK}", "ExitScript") HotKeySet("{PAUSE}", "ExitScript") Global $Array, $ArrayError Func ExitScript() If MsgBox(4, "Break", "Break gedrückt. Programm stoppen?") = 6 Then Exit EndFunc ;==>ExitScript #EndRegion Init While 1 ConsoleWrite(_Timer_GetIdleTime() & @CRLF) If _Timer_GetIdleTime() > 2000 Then ; 5 minutes 300000 ConsoleWrite("_Timer_GetIdleTime > 2000 " & @CRLF) GetWindow() If UBound($ArrayError) < 2 Then ; If no window found MouseClick("left", 1168, 727) ConsoleWrite("MouseClick left 1168, 727" & @CRLF) Sleep(500) MouseClick("left", 267, 574, 2) ConsoleWrite("MouseClick left 267, 574" & @CRLF) ConsoleWrite("_Timer_GetIdleTime after MouseClicks = " & _Timer_GetIdleTime() & @CRLF) If _Timer_GetIdleTime() > 6000 Then Notification() ConsoleWrite(" ==> Notification : _Timer_GetIdleTime > 6000" & @CRLF) EndIf EndIf EndIf Sleep(100) WEnd Func GetWindow() ;~ $Array = WinList("GUI") $ArrayError = WinList("ASAL-ALK Hauptmenu nicht gefunden") EndFunc ;==>GetWindow Func Notification() ;~ WinSetState("megumin","",@SW_SHOW) ;~ Sleep(2000) ;~ WinActivate("megumin") ;~ Sleep(2000) ;~ Send("{TAB}") ;~ Sleep(1000) ;~ Send($Array[1][0]) ;~ Sleep(1000) ;~ Send("{Enter}") ;~ Sleep(1000) ;~ Send("{!}") ;~ Send("highlight 0") ;~ Sleep(1000) ;~ Send("{Enter}") ;~ Sleep(1000) ;~ WinSetState("megumin","",@SW_HIDE) MsgBox(0, "Idle", "Bot could've stopped") ;~ WinSetState("megumin", "", @SW_SHOW) ;~ Sleep(1000) ;~ WinActivate("megumin") ;~ Send("{TAB}") ;~ Sleep(1000) ;~ Send($Array[1][0] & " checked") ;~ Sleep(1000) ;~ Send("{Enter}") ;~ Sleep(1000) ;~ WinSetState("megumin","",@SW_HIDE) EndFunc ;==>Notification EDIT : Additional note : You should never declare global variables inside a function, like in your version of GetWindow. Edited August 25, 2021 by Musashi "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
Chantaro Posted August 25, 2021 Author Share Posted August 25, 2021 Well yeah now that you've turned down the timer in the beginning to 2000 it obviously won't be, but in my post it is "12000" and not "2000", with that value it will most definitely be reached, but it still ignores the third If in the loop At first the timer is supposed to go to 12000 ticks, do the GetWindow func, the ubound check and click the mouse. If after all of that the machine is still idle after 6000 ticks it's supposed to send me the notification Is the way I coded it wrong or is there a better way to make this happen? Link to comment Share on other sites More sharing options...
Musashi Posted August 25, 2021 Share Posted August 25, 2021 47 minutes ago, Chantaro said: Well yeah now that you've turned down the timer in the beginning to 2000 it obviously won't be, but in my post it is "12000" and not "2000", with that value it will most definitely be reached, but it still ignores the third If in the loop No ! With your loop structure and conditional statements the third if part will not be reached even if you enter the value 12000 in the first If statement (try it). MouseClick resets the timer to 0, so If _Timer_GetIdleTime() > 6000 Then ... 'fails'. "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
Chantaro Posted August 25, 2021 Author Share Posted August 25, 2021 Yes I did try it! So how do I get the loop to not fully jump back to the beginning but rather go to the third If statement the next time 6000 is reached? Link to comment Share on other sites More sharing options...
Solution Musashi Posted August 25, 2021 Solution Share Posted August 25, 2021 Try this : expandcollapse popup#Region Init #include <AutoItConstants.au3> ;~ #include "ALK-Bots.au3" ;~ #include "Access_UDF.au3" #include <Array.au3> #include <MsgBoxConstants.au3> #include <File.au3> #include <FileConstants.au3> #include <Date.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <DateTimeConstants.au3> #include <Timers.au3> AutoItSetOption("WinTitleMatchMode", 2) ; Break für Abbruch HotKeySet("{BREAK}", "ExitScript") HotKeySet("{PAUSE}", "ExitScript") Global $Array, $ArrayError, $bSendNotification Func ExitScript() If MsgBox(4, "Break", "Break gedrückt. Programm stoppen?") = 6 Then Exit EndFunc ;==>ExitScript #EndRegion Init While 1 ConsoleWrite(_Timer_GetIdleTime() & @CRLF) If _Timer_GetIdleTime() > 12000 Then ; 5 minutes 300000 ConsoleWrite("_Timer_GetIdleTime > 12000 " & @CRLF) GetWindow() If UBound($ArrayError) < 2 Then ; If no window found MouseClick("left", 1168, 727) ConsoleWrite("MouseClick left 1168, 727" & @CRLF) Sleep(500) MouseClick("left", 267, 574, 2) ConsoleWrite("MouseClick left 267, 574" & @CRLF) ConsoleWrite("_Timer_GetIdleTime after MouseClicks = " & _Timer_GetIdleTime() & @CRLF) ; If the machine is still idle after 6000 ticks -> send a notification : $bSendNotification = False While Not $bSendNotification If _Timer_GetIdleTime() > 6000 Then $bSendNotification = True Notification() EndIf WEnd EndIf EndIf Sleep(100) WEnd Func GetWindow() ;~ $Array = WinList("GUI") $ArrayError = WinList("ASAL-ALK Hauptmenu nicht gefunden") EndFunc ;==>GetWindow Func Notification() ;~ WinSetState("megumin","",@SW_SHOW) ;~ Sleep(2000) ;~ WinActivate("megumin") ;~ Sleep(2000) ;~ Send("{TAB}") ;~ Sleep(1000) ;~ Send($Array[1][0]) ;~ Sleep(1000) ;~ Send("{Enter}") ;~ Sleep(1000) ;~ Send("{!}") ;~ Send("highlight 0") ;~ Sleep(1000) ;~ Send("{Enter}") ;~ Sleep(1000) ;~ WinSetState("megumin","",@SW_HIDE) MsgBox(0, "Idle", "Bot could've stopped") ;~ WinSetState("megumin", "", @SW_SHOW) ;~ Sleep(1000) ;~ WinActivate("megumin") ;~ Send("{TAB}") ;~ Sleep(1000) ;~ Send($Array[1][0] & " checked") ;~ Sleep(1000) ;~ Send("{Enter}") ;~ Sleep(1000) ;~ WinSetState("megumin","",@SW_HIDE) EndFunc ;==>Notification JockoDundee 1 "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
Musashi Posted August 25, 2021 Share Posted August 25, 2021 Addition : To let the main loop run again after the notification, you can insert ExitLoop. [...] ; If the machine is still idle after 6000 ticks -> send a notification : $bSendNotification = False While Not $bSendNotification If _Timer_GetIdleTime() > 6000 Then $bSendNotification = True Notification() ExitLoop EndIf WEnd [...] "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
Chantaro Posted August 25, 2021 Author Share Posted August 25, 2021 Thank you so much Musashi! In my case it still continues the Loop without the ExitLoop, but I'm still extremely grateful! Link to comment Share on other sites More sharing options...
Musashi Posted August 25, 2021 Share Posted August 25, 2021 1 minute ago, Chantaro said: Thank you so much Musashi! In my case it still continues the Loop without the ExitLoop, but I'm still extremely grateful! This is correct. My sentence should actually read : "You can insert ExitLoop instead of $bSendNotification = True". Anyway, the important thing is that it solves your problem . "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." 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