Jump to content

ControlClick() fails to work after script is built


Recommended Posts

Dear Ladies and Gentlemen,

The following part of a script toggles a wireguard tunnel. It works fine as long as I run the script hitting "F5" in Scite ("go").

The wireguard-client runs in my system tray.

Once the script is built and the resulting "exe" is executed, I receive an Error message: the ControlClick command returns 0.  All commands prior this have been tested using messageboxes - they work fine.

#include <Chrome.au3>
#include <GUIConstantsEx.au3>

Opt("WinTitleMatchMode", 2)
Opt("MouseCoordMode", 2)
Opt("MouseClickDelay", 20) ;10 milliseconds
Opt("SendKeyDelay", 20) ;5 milliseconds


HotKeySet("{F6}", "WG_Toggle")

;===TOGGLE WIREGUARD===
Func WG_Toggle()
    ;This Function toggles Wireguard tunnel
    
     Local $hWnd = WinWait ("WireGuard")
        If $hWnd = 0 Then msgbox(1,"Error WinWait", $hWnd)

    If ControlGetText($hWnd, "", "[CLASS:Button; INSTANCE:3]") = "&Activate" Then
        If ControlClick($hWnd, "&Activate", "[CLASS:Button; INSTANCE:3]") = 0 Then MsgBox(1, "Error while activating WG", "An error occured while activating Wireguard.")
    ElseIf ControlGetText($hWnd, "", "[CLASS:Button; INSTANCE:3]") = "&Deactivate" Then
        If ControlClick($hWnd, "&Deactivate", "[CLASS:Button; INSTANCE:3]") = 0 Then MsgBox(1, "Error while deactivating WG", "An error occured while deactivating Wireguard.")
    Else
        MsgBox(1, "Error", "WG function not responding")
    EndIf

EndFunc   ;==>WG_Toggle

 

Any comment that might help me to further troubleshoot the issue or how to achieve the toggle in an easier/more reliable way is much appreciated.

Thank you in advance!

 

 

Link to comment
Share on other sites

As described in help file :

When you use a window handle for the title parameter then the text parameter is completely ignored.

So changing it in any way, won't give a different result...

Link to comment
Share on other sites

There has been an update for WG-client. Now, I do not seem to achieve any effect with my controlclick command.

;===TOOGLE WIREGUARD===
Func WG_Toggle()
    ;This Function toggles Wireguard tunnel
    msgbox(1,"hello", "world",1)

    If WinExists("WireGuard") Then
        Local $hWnd = WinWait("WireGuard")
            If $hWnd = 0 Then msgbox(1,"Error WinWait", $hWnd)

        Msgbox(1,"Current status of WG", ControlGetText($hWnd, "", "[CLASS:Button; INSTANCE:3]"),1)

        If ControlGetText($hWnd, "", "[CLASS:Button; INSTANCE:3]") = "&Activate" Then
            ;ControlClick("WireGuard", "&Activate", "[CLASS:Button; INSTANCE:3]")
            WinActivate($hWnd)
            WinSetState ( $hWnd, "", @SW_MAXIMIZE )
            If ControlClick($hWnd, "", "[CLASS:Button; INSTANCE:3]") <> 7 Then MsgBox(1, "ControlClick executed", ControlClick($hWnd, "", "[CLASS:Button; INSTANCE:3]"))
        ElseIf ControlGetText($hWnd, "", "[CLASS:Button; INSTANCE:3]") = "&Deactivate" Then
            If ControlClick($hWnd, "", "[CLASS:Button; INSTANCE:3]") <> 7 Then MsgBox(1, "ControlClick executed", ControlClick($hWnd, "", "[CLASS:Button; INSTANCE:3]"))
        Else
            MsgBox(1, "Error", "WG function not responding")
        EndIf
    Else
        Msgbox(1,"Wireguard", "Wireguard is not running.",1)
    EndIf
Exit
EndFunc   ;==>WG_Toggle

Since the WG-tunnel isn't active, it is enough to trouble shoot the attempt to activate it. I get the following messages:

  1. "hello world" message,
  2. "Current status of WG": &activate
  3. "ControlClick executed": 1

But the WG-client does not react in any way.

Do you have a recommendation for another command that I could try? I would like to avoid mouseclicks...

Thank you.

 

 

 

 

 

 

Link to comment
Share on other sites

Why there is not any while loop to keep script alive or i am missing something? nwm its a part of script

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

i removed ;~ Opt("WinTitleMatchMode", 2) just to b safe

 

works for me compiled untill click part

#include <GUIConstantsEx.au3>

;~ Opt("WinTitleMatchMode", 2)
Opt("MouseCoordMode", 2)
Opt("MouseClickDelay", 20) ;10 milliseconds
Opt("SendKeyDelay", 20) ;5 milliseconds

HotKeySet("{F6}", "WG_Toggle")

While 1
    Sleep(10)
WEnd
;===TOOGLE WIREGUARD===
Func WG_Toggle()
    ;This Function toggles Wireguard tunnel

    If WinExists("WireGuard") Then
        Local $hWnd = WinGetHandle("WireGuard")
        If @error Then msgbox(1,"Error WinGetHandle", $hWnd)
        $check = WinActivate($hWnd)
        If $check  = 0 Then msgbox(1,"Error WinActivate", $hWnd)
        $check = WinWaitActive($hWnd)
        If $check = 0 Then msgbox(1,"Error WinWaitActive", $hWnd)

        Msgbox(1,"Current status of WG", ControlGetText($hWnd, "", "[CLASS:Button; INSTANCE:3]"),1)

        If ControlGetText($hWnd, "", "[CLASS:Button; INSTANCE:3]") = "&Activate" Then
            ;ControlClick("WireGuard", "&Activate", "[CLASS:Button; INSTANCE:3]")
            If ControlClick($hWnd, "", "[CLASS:Button; INSTANCE:3]") <> 7 Then MsgBox(1, "ControlClick executed", ControlClick($hWnd, "", "[CLASS:Button; INSTANCE:3]"))
        ElseIf ControlGetText($hWnd, "", "[CLASS:Button; INSTANCE:3]") = "&Deactivate" Then
            If ControlClick($hWnd, "", "[CLASS:Button; INSTANCE:3]") <> 7 Then MsgBox(1, "ControlClick executed", ControlClick($hWnd, "", "[CLASS:Button; INSTANCE:3]"))
        Else
            MsgBox(1, "Error", "WG function not responding")
        EndIf
    Else
        Msgbox(1,"WireGuard", "WireGuard is not running.")
    EndIf
EndFunc   ;==>WG_Toggle

But note that your calling 2 times controlclick one infront msgbox in if condittion and second time inside of msgbox itself!

 

edit: and btw ControlClick can return only 0 or 1 so i do not understand "<> 7"

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

Link to comment
Share on other sites

Hi guys,

thanks for your input. The button I want to click: 

image.thumb.png.f6923ae19c7424c71d3fcdbae8e3c5e0.png

 

7 is not a return value, correct. But I wanted to get the result in any case - for troubleshooting purposes, so I changed from 0 to 7... 🙂

I am in phone conferences right now - will come back to you ASAP.

 

 

 

Link to comment
Share on other sites

no because you have disable period after clicking on that button for that button

 

Problem is apparently something else:

While VPN window is active all autoit hotkeyes are disabled for some strange reason so hotkey will now work (at least for me). As soon as win is not in focus i can use declared hotkeys once more.

Control send focus or click already do not work (at least for me) on that button.

And no luck with Send()

 

Im confuzed :) 

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

  • The hotkeys do actually work in my case. 
  • And yes, of course: I executed the CommandClick twice - by mistake. This is why nothing happened anymore. Removing the second ComandClick in the msg-box, I was back to the original problem: it works as script, but fails as a compiled program.
  • I removed the  Opt("WinTitleMatchMode", 2) . No changes - except that other parts of the script don't work anymore. 🙂
  • So I tried the #RequireAdmin - and now it works!

Amazing thing: I spent several hours to save a few seconds now an then. While one should think that I am frustrated: it's always fun to work with autoit, and figure things out with the support of the forum! Thanks so much for your help everyone.

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...