Jump to content

Noob trouble with CtrlClick


Recommended Posts

Right, so i am making a program which checks if my internet is inactive, if so, it then calls this little script which in turn opens up a program in task manager and should then click a button which turns my 3g dongle off, wait 2 minutes and reclick the button to turn my dongle on again (essentially it is resetting my internet if and when my isp disconnects me).

With forum help i have already sorted out the internet check (works with server pings). And i found a topic which i borrowed code from to make the program pop up in taskbar. My problem now is with CtrlClick. I have done almost every variation of CtrlClick but nomatter what i do it doesn't click the button, it doesn't even seem to find the button. I am pretty sure thats because i am not declaring the Gui that is active?? or something along those lines. The task manager part works perfectly, it opens the program up, the problem definitely seems to reside with the whole CtrlClick() section. Anyhow here is my code if anyone feels like going over it and helping me solve this issue.

Eventually i am hoping to expand the code so that if my program crashes the script will startup the program .etc but i will work on that after CtrlClick is sorted out =)

Here is my code so far:

#Include <GuiToolBar.au3>

    Send("{CTRLDOWN}") ;send a <ctrl>-<esc> to bring up the Taskbar if it's hidden
    Send("{ESC}")
    Send("{CTRLUP}")
    Send("{ESC}") ;get rid of the Start Menu to avoid confusion
    Sleep(250)

Global $hSysTray_Handle, $iSystray_ButtonNumber

Global $sToolTipTitle = "Transferidos"  ; <<<<<<<<<<<<<<<< Enter some tooltip text for the icon you want here


$iSystray_ButtonNumber = Get_Systray_Index($sToolTipTitle)

If $iSystray_ButtonNumber = 0 Then
    MsgBox(16, "Error", "Icon not found in system tray")
    Exit
Else
    Sleep(500)
    _GUICtrlToolbar_ClickButton($hSysTray_Handle, $iSystray_ButtonNumber, "left")
    _GUICtrlToolbar_ClickButton($hSysTray_Handle, $iSystray_ButtonNumber, "left")
    Sleep(1000)
    ControlClick("[CLASS:TlmButton]", "left", "[ID:262988]", 41, 11)
EndIf

Exit

;............

Func Get_Systray_Index($sToolTipTitle)

    ; Find systray handle
    $hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]')
    If @error Then
        MsgBox(16, "Error", "System tray not found")
        Exit
    EndIf

    ; Get systray item count
    Local $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle)
    If $iSystray_ButCount = 0 Then
        MsgBox(16, "Error", "No items found in system tray")
        Exit
    EndIf

    ; Look for wanted tooltip
    For $iSystray_ButtonNumber = 0 To $iSystray_ButCount - 1
        If StringInStr(_GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber), $sToolTipTitle) = 1 Then ExitLoop
    Next

    If $iSystray_ButtonNumber = $iSystray_ButCount Then
        Return 0 ; Not found
    Else
        Return $iSystray_ButtonNumber ; Found
    EndIf

EndFunc

A "Pre-Thank You" for anyone who helps me.

CarVeR

Link to comment
Share on other sites

Just to add that i've tried so many different combinations for CtrlClick that my fingers hurt. Here are a few examples:

ControlClick("[CLASS:TlmButton; INSTANCE:13]", "left", 41, 11)

ControlClick("Desligar", "left", "[iD:262988]", 41, 11)

Honestly... you get the idea, i've tried with/out id's and all sorts, with different mouse locations aswell.

Link to comment
Share on other sites

The syntax for controlclick:

ControlClick ( "title", "text", controlID [, button [, clicks [, x [, y ]]]] )

I am assuming the title of the window is Desligar??

What is 41,11 < What are you trying to do here? (It looks like the x/y coords, but it's at the wrong place)

This should work, as long as the Title and ID are correct

Opt("Wintitlematchmode",2)
ControlClick("Desligar", "", "[ID:262988]")

Also in this section

Sleep(500)
    _GUICtrlToolbar_ClickButton($hSysTray_Handle, $iSystray_ButtonNumber, "left")
    _GUICtrlToolbar_ClickButton($hSysTray_Handle, $iSystray_ButtonNumber, "left")
    Sleep(1000)
    ControlClick("[CLASS:TlmButton]", "left", "[ID:262988]", 41, 11)

You use sleep(1000), are you waiting for a window to appear here (The "Desligar" window?)

Rather use

WinWaitActive("Desligar")

or

while WinExists("Desligar") = 0
sleep(100)
WEnd

This way you are sure that the window has popup up

Edited by hawky358
Link to comment
Share on other sites

It still isn't working, I have added the WinWaitActive function and thats working so my title works which is "MODEM Mobile Connection".

But it will not click the button for the life of it, i've tried ID and Instance too.

Those numbers were the ControlClick Coordinates, but they never worked.

Link to comment
Share on other sites

Try using

ControlDisable("MODEM Mobile Connection","","[CLASS:TlmButton; INSTANCE:13]")

to see if it greys out the button, if it does and the click doesn't work with the exact same settings (remember to enable again first) then maybe that window can't be controlled using this method. (I've seen this on the IE save window as well)

If the button doesn't grey out then somewhere the ID or something is wrong.

As an alternative I guess you can use normal send to TAB TAB SPACE and click it like that...

Edited by hawky358
Link to comment
Share on other sites

Just tried that and it didn't grey out. =( i must say it is a very awkward program at all times, so it wouldn't surprise me if it cannot be clicked this way.

After seeing the pic, I'm not sure if it will grey out. It doesn't look like a normal button in the sense that it will grey out.

One last thing you can check maybe try

ControlGetText("MODEM Mobile Connection","","[CLASS:TlmButton; INSTANCE:13]")

to see if you get that Desligar returned.

Does it work if you just activate that window and send an enter?

Link to comment
Share on other sites

In the output window i get "Exit code>0"

Just note, I didn't add a consolewrite(), I am assuming you did.

Maybe you should try with

Opt("Wintitlematchmode",2)

Make your title just "MODEM" instead of MODEM .....

Send("Enter") doesn't work.

What about tabbing util selected and then SPACE? :idea: Edited by hawky358
Link to comment
Share on other sites

i didn't add consolewrite.

Where should i add that ?

Sorry i am a complete and total noob, all this coding is probably way out of my league, but i tend to learn as i do things Lol.

Link to comment
Share on other sites

Hmm, yea if

Controlclick("MODEM Mobile Connection","","[CLASS:TlmButton; INSTANCE:13]")

doesn't work then it seems like you won't be able to do it like this.

Try to find a keyboard combination that will allow you to "click" that button

Send() should work since it just sends it to the window instead of the control

Link to comment
Share on other sites

i don't suppose i can use MouseMove and MouseClick somehow to do this? My window is unlikely to ever move from its current location, so i don't think the mouse location should matter.

Link to comment
Share on other sites

Its strange because AutoItRecord doesn't record any mouseclicks that i make on that program, it would be nice if there was some way of finding out what happens when the buttons are clicked so i could call a dll or something rather than click the button. But i don't know anything about that kind of stuff Lol.

Link to comment
Share on other sites

Yea it's odd.

You can TRY mouseclick(), but I've tried it with the IE save dialogue (which shows similar behaviour) and it doesn't work.

it would be nice if there was some way of finding out what happens when the buttons are clicked so i could call a dll or something rather than click the button.

Yea, I can't say.

Try checking these alternatives

Isn't there a connection under "Networking" which you can reconnect or do you HAVE to disable and enable the dongle?

Maybe it's running a service? - Then you can just restart the service

Does it work if you disable then enable the device (USB dongle) is Device manager - Then you can use Devcon

Link to comment
Share on other sites

The dongle seems to run through the program, i can connect through windows 7's connect, but i cannot disconnect or refresh the connection if my net goes down. There is no service, i just disabled/enabled but the program doesn't automatically reconnect so i am left stuck again until i press "Ligar" (Connect) Button on the program.

What a nightmare!!

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