Jump to content
Skysnake

Automate C legacy GUI - ControlCommand & ControlClick not working

Recommended Posts

Skysnake

I need to automate a specific GUI from a legacy system written in C.

The spy tool gives me this

spy1.png.32508e0a16e4406192657891d770f3fe.png

I use this code

Local $swintit = WinGetTitle("[active]")
    ConsoleWrite("active Window " & $swintit & @CRLF)

    If $swintit = "FILES NOTES" Then ; If $swintit = "FILES NOTES" Then
        ; got Window, now atomate
        ConsoleWrite("got Window " & @CRLF)

        ; now focus, then click :)

        ;EditPaste
        ;ControlCommand("FILES NOTES", "", 404, $acno) ; paste acno
        GUICtrlSetState(404, $GUI_Focus)
        ControlCommand("FILES NOTES", "", 404, $acno) ; paste acno
        GUICtrlSetState(401, $GUI_Focus)
        ControlClick("FILES NOTES", "", 401, $acno) ; click okay

    EndIf ; If $swintit = "FILES NOTES" Then

The idea is to paste the acno value into the edit box, then click an Okay button.

I get a console write that the active Window is as expected, but my loop completes without ever writing anything into the GUI.

I also tried the control ID as text "404" - same result

What am I missing?

Skysnake

 


Skysnake

Why is the snake in the sky?

Share this post


Link to post
Share on other sites
Danp2

Not sure that you can use the ID number from AU3Info like that. Instead I would use the info under advanced mode, Also, there seems to be some syntax issues in your code.

Have you tried either of these methods? --

ControlSetText("FILES NOTES", "", "[CLASS:Edit, INSTANCE:1]", $acno)

or

ControlFocus("FILES NOTES", "", "[CLASS:Edit, INSTANCE:1]")
ControlCommand("FILES NOTES", "", "[CLASS:Edit, INSTANCE:1]", "EditPaste", $acno) ; paste acno

 

  • Like 1

Share this post


Link to post
Share on other sites
Skysnake

Thx. :)

Same result. Copied your code directly into my script, still does nothing. 

Please just point me in some direction? What can I use? I have never done this and feel a bit lost. 

Based on the overwhelming responses I am guessing this is not a common activity :)

Thanks again.

Skysnake


Skysnake

Why is the snake in the sky?

Share this post


Link to post
Share on other sites
Danp2

Add some error checking. Each of these commands should return a value indicating either success or failure.

You could also try using ControlSend.

  • Like 1

Share this post


Link to post
Share on other sites
Danyfirex

Hello. try to show more information of AutoIt v3 Window Info to be sure what kind of control you're trying to handle.

 

Saludos

Share this post


Link to post
Share on other sites
Earthshine

you have no logging or debug messages in msgbox form even in the area you want to test. does it find your dialog form even?


My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
Skysnake
Posted (edited)

Am I making some kind logic error?

I am running Win10 64 bit.

 

The legacy software was designed for Windows XP and is 32 bit. (It still works on the Win 10 64 bit box)

 

Modified code

Local $retunValue = 0, $returnedError

    ConsoleWrite("got $acno " & $acno & @CRLF)

    Local $swintit = WinGetTitle("[active]")
    ConsoleWrite("active Window [" & $swintit & "]" & @CRLF)
    Local $hWin = WinGetHandle("[active]")
    WinActivate($hWin)

    ;active Window [FILE NOTES]
    If $swintit = "FILE NOTES" Then ; If $swintit = "FILES NOTES" Then
        ; got Window, now atomate
        ConsoleWrite("got Window " & @CRLF)

        ; now focus, then click :)

        ;EditPaste
        ;ControlCommand("FILES NOTES", "", 404, $acno) ; paste acno
        $retunValue = ControlFocus("FILE NOTES", "", "[CLASS:Edit, INSTANCE:1]")
        ConsoleWrite("10 $retunValue " & $retunValue & @CRLF)
        $returnedError = @error
        ConsoleWrite("10 @error " & $returnedError & @CRLF)
        $retunValue = ControlCommand("FILE NOTES", "", "[CLASS:Edit, INSTANCE:1]", "EditPaste", $acno) ; paste acno
        ConsoleWrite("20 $retunValue " & $retunValue & @CRLF)
        $returnedError = @error
        ConsoleWrite("20 @error " & $returnedError & @CRLF)
        Sleep(250)
        $retunValue = ControlFocus("FILE NOTES", "", "[CLASS:Edit, INSTANCE:1]")
        ConsoleWrite("30 $retunValue " & $retunValue & @CRLF)
        $returnedError = @error
        ConsoleWrite("30 @error " & $returnedError & @CRLF)
        $retunValue = ControlClick("FILE NOTES", "", "[CLASS:Edit, INSTANCE:1]")
        ConsoleWrite("40 $retunValue " & $retunValue & @CRLF)
        $returnedError = @error
        ConsoleWrite("40 @error " & $returnedError & @CRLF)
        Sleep(1000)

    EndIf ; If $swintit = "FILE NOTES" Then

 

Console Output
got $acno AP0050
active Window [FILE NOTES]
got Window 
10 $retunValue0
10 @error 0
20 $retunValue0
20 @error 0
30 $retunValue0
30 @error 0
40 $retunValue0
40 @error 0

 

Edited by Skysnake

Skysnake

Why is the snake in the sky?

Share this post


Link to post
Share on other sites
Skysnake

Here is the spy shot for the button

spy2.png.d87282a85b2967927962e69160953b00.png

What else could be relevant?  Where can I look?


Skysnake

Why is the snake in the sky?

Share this post


Link to post
Share on other sites
Danyfirex

get the @error value before consolewrite.

 

 

Saludos

Share this post


Link to post
Share on other sites
Danyfirex

Also Run your Script with admin rights.

 

 

Saludos

Share this post


Link to post
Share on other sites
Skysnake
Posted (edited)

Changes made as suggested.  :)

Still no usable result

updated code, with #RequireAdmin at the top

Local $returnValue = 0, $returnedError

    ConsoleWrite("got $acno " & $acno & @CRLF)

    Local $swintit = WinGetTitle("[active]")
    ConsoleWrite("active Window [" & $swintit & "]" & @CRLF)
    Local $hWin = WinGetHandle("[active]")
    WinActivate($hWin)

    ;active Window [FILE NOTES]
    If $swintit = "FILE NOTES" Then ; If $swintit = "FILES NOTES" Then
        ; got Window, now atomate
        ConsoleWrite("got Window " & @CRLF)

        ; now focus, then click :)

        ;EditPaste
        ;ControlCommand("FILES NOTES", "", 404, $acno) ; paste acno
        $returnValue = ControlFocus("FILE NOTES", "", "[CLASS:Edit, INSTANCE:1]")
        $returnedError = @error
        ConsoleWrite("110 @error " & $returnedError & @CRLF)
        ConsoleWrite("110 $returnValue " & $returnValue & @CRLF)

;~      $returnValue = ControlCommand("FILE NOTES", "", "[CLASS:Edit, INSTANCE:1]", "EditPaste", $acno) ; paste acno
;~      ConsoleWrite("20 $returnValue " & $returnValue & @CRLF)
;~      $returnedError = @error
;~      ConsoleWrite("20 @error " & $returnedError & @CRLF)

        $returnValue = ControlClick("FILE NOTES", "", "[CLASS:Edit, INSTANCE:1]", "", Default, 21, 9) ; paste acno
        $returnedError = @error
        ConsoleWrite("210 @error " & $returnedError & @CRLF)
        ConsoleWrite("210 $returnValue ControlClick " & $returnValue & @CRLF)

        $returnValue = ControlSetText("FILE NOTES", "", "[CLASS:Edit, INSTANCE:1]", $acno) ; paste acno
        $returnedError = @error
        ConsoleWrite("220 @error " & $returnedError & @CRLF)
        ConsoleWrite("220 $returnValue ControlSetText " & $returnValue & @CRLF)

        Sleep(250)
        $returnValue = ControlFocus("FILE NOTES", "", "[CLASS:Edit, INSTANCE:1]")
        $returnedError = @error
        ConsoleWrite("230 @error " & $returnedError & @CRLF)
        ConsoleWrite("230 $returnValue " & $returnValue & @CRLF)
        $returnValue = ControlClick("FILE NOTES", "", "[CLASS:Edit, INSTANCE:1]")
        $returnedError = @error
        ConsoleWrite("240 @error " & $returnedError & @CRLF)
        ConsoleWrite("240 $returnValue " & $returnValue & @CRLF)
        Sleep(1000)

    EndIf ; If $swintit = "FILE NOTES" Then

Console output

55 IsAdmin Admin rights are detected
_clickGui 09-Apr-18 4:48:30 PM
got $acno ACNO
active Window [FILE NOTES]
got Window 
110 @error 0
110 $returnValue 0
210 @error 0
210 $returnValue ControlClick 0
220 @error 0
220 $returnValue ControlSetText 0
230 @error 0
230 $returnValue 0
240 @error 0
240 $returnValue 0

 

Edited by Skysnake

Skysnake

Why is the snake in the sky?

Share this post


Link to post
Share on other sites
Earthshine
Posted (edited)

LOL. ok. Back up for a minute. You look for your text, then do something, however, what if there are other windows present while running? you are not looping through the processes. Your method of getting your window needs lots of work and can be done with a run, or runwait command probably, then a simple controlclick

what is the name of the process you run? we can go from there. Your code is really not up to the task as is.

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
Skysnake

:)

Can't find the hysterical smiley :)

But, THIS works...

_ClipBoard_SetData($acno)
_ClipBoard_GetData()
Send("^V")
Send("!O")

So, after all the focusing on the controls, I copy my data to the Clipboard and then simply paste it.  This is giving me what I want.  

:)

 


Skysnake

Why is the snake in the sky?

Share this post


Link to post
Share on other sites
InnI
2 hours ago, Skysnake said:

$returnValue = ControlSetText("FILE NOTES", "", "[CLASS:Edit, INSTANCE:1]", $acno) ; paste acno

To separate the properties you need to use ";" but not ","

$returnValue = ControlSetText("FILE NOTES", "", "[CLASS:Edit;INSTANCE:1]", $acno) ; paste acno

Or simply

$returnValue = ControlSetText("FILE NOTES", "", "Edit1", $acno) ; paste acno

 

  • Like 1

Share this post


Link to post
Share on other sites
Skysnake
20 hours ago, InnI said:

To separate the properties you need to use ";" but not ","

Hmm. thx. will try. The devil is always in the detail. :)

 


Skysnake

Why is the snake in the sky?

Share this post


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

  • Similar Content

    • Yirrlaar
      By Yirrlaar
      #Include <WinAPI.au3> local $ClassName = _WinAPI_GetClassName(WinGetHandle(WinGetTitle("[ACTIVE]"))) ControlClick(WinGetTitle("[ACTIVE]"), "", "[CLASS:"&$ClassName&"; INSTANCE:1]", "primary") When I am running this script it just gives me a ConsoleWrite output of "0x001D04A8"
      When using "AutoIT v3 Window Info" all the info I need for the ControlClick is there and displayed perfectly as if I typed it in normally.
      Upon click the button it should be clicking it, I see the following inn the console window:
      If I replace the $ClassName with the actual ClassName of "WindowsForms10.BUTTON.app.0.3296db7_r14_ad1" it works just fine, any ideas???
    • Silas
      By Silas
      Hello everyone,
      I have a radio button ($Radio1), which I want to disable as soon as another one get's checked (Radio5). (The system fails if the radio button i'm troubling with also gets checked).
      I know how to disable him:
      If GUICtrlRead($Radio1)=1 And Not BitAND(GUICtrlGetState($Radio5), $GUI_DISABLE) Then GUICtrlSetState($Radio5, 128) But if i try to enable $Radio5 again, after $Radio1 isn't checked anymore, it fails:
      If GUICtrlRead($Radio1)=Not 1 And Not BitAND(GUICtrlGetState($Radio5), $GUI_ENABLE) Then GUICtrlSetState($Radio5, 64)  
      Anyone knows why?
    • Tats
      By Tats
      Hi everyone,
      I have a problem with ControlClick function. It doesn't work no matter how I tried all the possible combination of the parameters.
      Below is the scripts of possible parameter combination:
      ;ControlClick("title","text","controlID ","button","clicks","x","y") ;title= Title, Class, Handle ;controlID= Class, ClassNN, Instance ;Title here is empty when I check it with AutoIt Info ControlClick("", "", "[ScreenKeyboard::Button18]", "left", "1", "230","890") ControlClick("", "", "[CLASS:ScreenKeyboard::Button; INSTANCE:18]", "left", "1", "230","890") ControlClick("", "", "[INSTANCE:18]", "left", "1", "230","890") ;Title here is the Class of the window ControlClick("[ScreenKeyboard::SKFrame]", "", "[ScreenKeyboard::Button18]", "left", "1", "230","890") ControlClick("[ScreenKeyboard::SKFrame]", "", "[CLASS:ScreenKeyboard::Button; INSTANCE:18]", "left", "1", "230","890") ControlClick("[ScreenKeyboard::SKFrame]", "", "[INSTANCE:18]", "left", "1", "230","890") ;Title here is the Handle of the window ControlClick("[0x000907A0]", "", "[ScreenKeyboard::Button18]", "left", "1", "230","890") ControlClick("[0x000907A0]", "", "[CLASS:ScreenKeyboard::Button; INSTANCE:18]", "left", "1", "230","890") ControlClick("[0x000907A0]", "", "[INSTANCE:18]", "left", "1", "230","890") Am I coding it correctly?
      Thanks
    • MaximusCZ
      By MaximusCZ
      Hello, and apologies if this have been discussed before, but I googled and couldnt find anything relevant.
      I have a problem where I try to send a control clink into to a window. 
      Part of window I try to send clicks to looks like this . The black border is showing when I mouse over it Au3Info, I get following information:

      I am testing its interaction with code

      The result I get is that it makes control clicks trough first line, opens and closes menus, as expected.
      When It gets to second line, it does not click a single icon. I can tell that coords are correct as the dropdown menus (No view active) gets focused(altough not rolled out). Same behaviour happens if roughly 40<y<60, so I know I am hitting good height. You can look at how it behaves here: output.webm 
      Dropdown 1 focuses at around 8 sec mark, and 13 sec mark it changes to second dropdown, defocusing first one, seemingly not registering any clinks inbetween.
       
      Have you ever encountered similar behaviour? I need to click the Key button, first on second line, with controlclick (or any other way not hijacking the mouse). I cant trigger that button by keyboard and There is no other control having control over it.
      Help
       
    • JNutt
      By JNutt
       

       
       
      I'm trying to use mouseclick in a panel above.  I want to click on a list item, such as 'Estimated'.  (I've given up on trying to use control click for this).  I'm using window info coordinates from 'Control' tab.

      ; click 'Columns' WinActivate("Innovaya Studio with Sage (Archtectural 2017_V1.invx") MouseClick("primary", 292, 88, 1, 1) WinActivate("Select Browsing Properties") Sleep(1000) MouseClick("primary", 27, 70, 0,0) Sleep(2000) Send("{TAB}{TAB}{TAB}{TAB}{TAB}") Sleep(1000) Send("{ENTER}") ControlClick( But when I used the code Autoit doesn't click where the coordinates are.  In the scipts it is the second MouseClick that won't work.  Any ideas?
×