melihtozlu Posted March 15, 2023 Posted March 15, 2023 Hello, here's what I am trying to do: I want Anydesk to run permanently in the background for me, and if this application is not running, that it will be started. I have the working code for this, that works. But now, when a connection request arrives, I want Autoit to always accept it automatically. But the new window that appears has the same title, so I'm having trouble making that happen. In short: I want to write a code that firstly checks (first goal) if Anydesk is running in the background and if not, that it starts that and secondly that always accepts connection requests (so even after disconnecting from the other device, for example). This is the code I tried it with (works until the first goal): While 1 If Not ProcessExists('AnyDesk.exe') Then Run('C:\Program Files (x86)\AnyDesk\AnyDesk.exe') EndIf Sleep(250) If WinExists("AnyDesk", "[CLASS:basic_button#9; INSTANCE:1]") Then WinActivate("AnyDesk", "[CLASS:basic_button#9; INSTANCE:1]") WinWaitActive("AnyDesk", "[CLASS:basic_button#9; INSTANCE:1]") sleep(1500) ControlClick('AnyDesk', '', '[CLASS:basic_button#9; INSTANCE:1]') EndIf WEnd
mistersquirrle Posted March 15, 2023 Posted March 15, 2023 Check out WinList: https://www.autoitscript.com/autoit3/docs/functions/WinList.htm You can keep an array of windows so you know which ones exist, and use WinList to see if there's a new window with the same title, or just loop through all of the windows to see if there's one to do some action on. Also, you're using most of these Win* functions wrong, the second parameter is for window text, but you're passing in Control names/classes, which will likely make none of those window functions work. Just use an empty string ('') for the text field, unless you use the AutoIt Window Info tool to verify the text in the window ( like "Accept Connection" ). So try something like this: AutoItSetOption('WinTitleMatchMode', 2) ; 2 = Match any substring in the title Global $aWinList = WinList('AnyDesk') Global $hCtrl While 1 If Not ProcessExists('AnyDesk.exe') Then Run('C:\Program Files (x86)\AnyDesk\AnyDesk.exe') EndIf Sleep(250) $aWinList = WinList('AnyDesk') If IsArray($aWinList) And $aWinList[0][0] > 0 Then For $iWindow = 1 To $aWinList[0][0] ConsoleWrite('Checking window ' & $aWinList[$iWindow][1] & ', title: ' & $aWinList[$iWindow][0] & @CRLF) $hCtrl = ControlGetHandle($aWinList[$iWindow][1], '', '[CLASS:basic_button#9; INSTANCE:1]') ; Use the window handle from the list, and check for the Control for the button you want, see if it exists. Hopefully it only exists on the window that you want If Not @error Then ; Only do something if the control was found ConsoleWrite('Button found ' & $hCtrl & ', clicking...' & @CRLF) ControlClick('AnyDesk', '', $hCtrl) Sleep(1000) ExitLoop EndIf Next EndIf WEnd We ought not to misbehave, but we should look as though we could.
ioa747 Posted March 15, 2023 Posted March 15, 2023 (edited) without wanting to become ordinary you know that the AnyDesk has such a setting, and that you don't need any script to achieve this Edited April 3, 2023 by ioa747 I know that I know nothing
melihtozlu Posted March 15, 2023 Author Posted March 15, 2023 6 hours ago, mistersquirrle said: Check out WinList: https://www.autoitscript.com/autoit3/docs/functions/WinList.htm You can keep an array of windows so you know which ones exist, and use WinList to see if there's a new window with the same title, or just loop through all of the windows to see if there's one to do some action on. Also, you're using most of these Win* functions wrong, the second parameter is for window text, but you're passing in Control names/classes, which will likely make none of those window functions work. Just use an empty string ('') for the text field, unless you use the AutoIt Window Info tool to verify the text in the window ( like "Accept Connection" ). So try something like this: AutoItSetOption('WinTitleMatchMode', 2) ; 2 = Match any substring in the title Global $aWinList = WinList('AnyDesk') Global $hCtrl While 1 If Not ProcessExists('AnyDesk.exe') Then Run('C:\Program Files (x86)\AnyDesk\AnyDesk.exe') EndIf Sleep(250) $aWinList = WinList('AnyDesk') If IsArray($aWinList) And $aWinList[0][0] > 0 Then For $iWindow = 1 To $aWinList[0][0] ConsoleWrite('Checking window ' & $aWinList[$iWindow][1] & ', title: ' & $aWinList[$iWindow][0] & @CRLF) $hCtrl = ControlGetHandle($aWinList[$iWindow][1], '', '[CLASS:basic_button#9; INSTANCE:1]') ; Use the window handle from the list, and check for the Control for the button you want, see if it exists. Hopefully it only exists on the window that you want If Not @error Then ; Only do something if the control was found ConsoleWrite('Button found ' & $hCtrl & ', clicking...' & @CRLF) ControlClick('AnyDesk', '', $hCtrl) Sleep(1000) ExitLoop EndIf Next EndIf WEnd That didn't work sadly, but I will use the more "easier solution" below. Thanks for your help though!
melihtozlu Posted March 15, 2023 Author Posted March 15, 2023 6 hours ago, ioa747 said: without wanting to become ordinary you know that the AnyDesk has such a setting, and that you don't need any script to achieve this Yeah, I definitely didn't know about this one! Thanks!!
mistersquirrle Posted March 15, 2023 Posted March 15, 2023 Definitely, if there's an easier way to do what you want, take it for sure. I'm not familiar with AnyDesk. If you do ever go back to the code though, the problem that may exist with what I posted is the ControlId "[CLASS:basic_button#9; INSTANCE:1]". I don't use AnyDesk so can't test but "basic_button#9" seems odd to me. So if you do some back to it double check what the button ID is in the AutoIt Window Info tool. We ought not to misbehave, but we should look as though we could.
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