Jump to content

Go to function at the end of the script instead of exiting


 Share

Recommended Posts

Hello this is the code maybe you can figure it out I placed some comments to try and explain what I want

#include <Array.au3>

AnyDeskOpen()

Func AnyDeskOpen()
      Global  $aWinList = WinList("[REGEXPTITLE:(?i)(.*Anydesks*)]")   ;get window name and handle from windows and store into an array
      $asd = $aWinList
      $aExtract = _ArrayExtract($asd)                                   ; beginner babble clean this Sh** up 
      Global $default = _ArrayToString($aExtract, "", 0, 0)
EndFunc

StartWait()                                                     ; check in the array to see how many windows are opened
Func StartWait()
While 1
AnyDeskOpen()

If $Default = 1 Then
   Sleep (3500)
                Else
      Exitloop
   EndIf
WEnd
EndFunc

If $default = "2" Then                                          ; If two windows are opened than someone is trying to connect to that computer and needs a click to accept connection try and click accept Button in the first window and the second one by activating diffrent window handle 


    $extra = _ArrayToString($aWinList, "", 1, 1)
    $sString = StringReplace($extra, "AnyDesk", "")
   $hGUI = $sString
   WinActivate(HWnd($hGUI))
   winmove (HWnd($hGUI), "", 50, 50)
   Mouseclick ("left", 100, 500)


   Sleep (1500)

   $extra = _ArrayToString($aWinList, "", 2, 2)
    $sString = StringReplace($extra, "AnyDesk", "")
   $hGUI = $sString
   WinActivate(HWnd($hGUI))
   winmove (HWnd($hGUI), "", 50, 50)
   Mouseclick ("left", 100, 500)

EndIf


While 1                                                               ;up to here everything seems to work
AnyDeskOpen()                                                           ; while there is a connection there are two AnyDesk windows,  if we close the connection than only one window remains opened and we check the array to see how many values it has
If $Default = 2 Then    
   Sleep (3500)
Else                                                                        ; At this  point the program exits code 0 instead of resseting to function above   
     StartWait()
      Exitloop

   EndIf
WEnd                                                                      ; thank you

 the intent is to keep the program going so it clicks accept again when reconnecting

Link to comment
Share on other sites

Here is another way, untested (don't have AnyDesk).

#include <Array.au3>
HotKeySet("{ESC}", "_ExitScript")   ;~ Press Escape to Exit script.

Global $g_aAnyDeskSessions[1][2] = WinList("[REGEXPTITLE:(?i)(.*AnyDesk*)]")    ;~ Count number of AnyDesk Windows

AdlibRegister("_AnyDeskSessions")

While 1
    Sleep(100)
WEnd

Func _AnyDeskSessions()
    Local $aAnyDeskSessions = WinList("[REGEXPTITLE:(?i)(.*AnyDesk*)]") ;~ Get number of AnyDesk Windows
    If $aAnyDeskSessions[0][0] = $g_aAnyDeskSessions[0][0] Then Return  ;~ Compare against the global array, no changes return
    Switch $aAnyDeskSessions[0][0]  ;~ AnyDesk Window count has changed
        Case 0
            $g_aAnyDeskSessions = $aAnyDeskSessions ;~ No AnyDesk Windows are open, update global array and return
            Return
        Case 1
            $g_aAnyDeskSessions = $aAnyDeskSessions ;~ 1 AnyDesk Window is open, update global array and return
            Return
        Case Else   ;~ Multiple Windows are open
            For $i = 1 To $aAnyDeskSessions[0][0]   ;~ Loop through all sessions to check if it's been activated by searching the global array for the handle
                If _ArraySearch($g_aAnyDeskSessions, $aAnyDeskSessions[$i][1], 1, 0, 0, 0, 1, 1) = -1 Then
                    WinMove($aAnyDeskSessions[$i][1], "", 150, 150)
                    MouseClick("left", 100, 500)
                EndIf
            Next
            $g_aAnyDeskSessions = $aAnyDeskSessions ;~ Update global array and return
    EndSwitch
EndFunc

Func _ExitScript()
    Exit
EndFunc

 

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

×
×
  • Create New...