Jump to content

_Timer_GetIdleTime won't trigger


Go to solution Solved by Musashi,

Recommended Posts

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:

#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 post
Share on other sites

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 by pseakins
variable naming, workaround

Phil Seakins

Link to post
Share on other sites

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 post
Share on other sites

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)...

Link to post
Share on other sites

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 by Nine
Link to post
Share on other sites

runnable script

#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 post
Share on other sites
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)

#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 by Musashi

Musashi-C64.png

"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 post
Share on other sites

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 post
Share on other sites
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'.

Musashi-C64.png

"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 post
Share on other sites
  • Solution

Try this :

#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

 

Musashi-C64.png

"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 post
Share on other sites

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

[...]

 

Musashi-C64.png

"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 post
Share on other sites
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 :lol:.

Musashi-C64.png

"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 post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...