Jump to content
Sign in to follow this  
Skysnake

Automate C legacy GUI - ControlCommand & ControlClick not working

Recommended Posts

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

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

 

Share this post


Link to post
Share on other sites

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

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

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

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

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

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

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

 

Share this post


Link to post
Share on other sites
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Yodavish
      My AutoIt script works fine, for the most part, however, if it goes idle for roughly 30 minutes, it will won't be able to send data to a 3rd party application window titled, "Case #". 
      The problem lies within the function "SendFusion", it's able to see the handle for the "WinActivate" and "WinWaitActivate" (I've also tried putting in 10 seconds in the WinWaitActivate as well, doesn't work). However, if we have been idle, it will always fail to send data afterward. On what I've tried so far:
      "Send" function with the data and a {ENTER} i.e. Send($CaseTxt & "{ENTER}"), this won't even hit the enter key  ControlSetText, tried passing the handle from WinActivate, using the title "Case #" that was copied directly from the Autoit Window Info, hard coding the title, Using CLASS:WindowsForms10... always returns a 0 ControlCommand (same as above) always returns a 0 ControlGetFocus always returns a 0 ControlFocus, always returns a 0 Creating a new and simple Au3 script that just sends data to "Case #", also fails NOTE: If I close the Au3 script and just scan the data directly into the "Case #" or even type it, it works fine with no issues. I'm confused as to why it would not work after a long idle period?
      Below are the essential parts of the script, I can provide the entire thing if needed. Any suggestions would be greatly appreciated!
      #include <AutoItConstants.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <Process.au3> #include <Misc.au3> #include <IE.au3> ;--------------------------------------------------------------- ; Only one instance can run ;--------------------------------------------------------------- If _Singleton("gross.exe", 1) = 0 Then MsgBox($MB_SYSTEMMODAL, "Warning", "Gross.exe is already running. Please exit the existing version first (check the icons in the lower right corner of your screen) before running it again.") Exit EndIf ;--------------------------------------------------------------- ; AutoIt Options ;--------------------------------------------------------------- Opt("GUIOnEventMode", 1) ; Change to OnEvent mode Opt("WinWaitDelay", 0) ; Alters how long a script should briefly pause after a successful window-related operation. Time in milliseconds to pause (default=250). Opt("WinTextMatchMode", 1) ; Alters the method that is used to match window text during search operations. 2 = Quick mode Opt("SendKeyDelay", 0) ; Alters the length of the brief pause in between sent keystrokes. A value of 0 removes the delay completely. Time in milliseconds to pause (default=5). if ($fusionWindowTitle="NONE" or $fusionCaseNumWinTitle="NONE" or $appWindowTitle="NONE" or $winActivateTimeout="NONE" or $winCloseTimeout="NONE" or $winWaitTimeout="NONE" or $pdfViewerWidth="NONE" or $pdfViewerHeight="NONE" or $pdfViewerLeft="NONE" or $pdfViewerWindowName="NONE" or $pdfViewerExeName="NONE" or $pdfUrl="NONE" or $pdfDownloadCommand="NONE") Then Msgbox(0,"ERROR", "gross.ini is missing or does not contain all settings. Please contact Help Desk with this information") Exit -1 EndIf ;--------------------------------------------------------------- ; application settings/constants ;--------------------------------------------------------------- Global Const $[VARIABLE] = IniRead("gross.ini", "default", "[TitleOfVariable]", "NONE") Global Const $[VARIABLE] = IniRead("gross.ini", "default", "[TitleOfVariable]", "NONE") Global Const $[VARIABLE] = IniRead("gross.ini", "default", "[TitleOfVariable]", "NONE") Global Const $[VARIABLE] = IniRead("gross.ini", "default", "[TitleOfVariable]", "NONE") ;--------------------------------------------------------------- ; create the main window ;--------------------------------------------------------------- Local $mainWindow = GUICreate($appWindowTitle, 380, 190) ; create the main GUI window GUISetOnEvent($GUI_EVENT_CLOSE, "handleCloseClick") ; when the click the windows close button call handleCloseClick() WinSetOnTop($appWindowTitle, '', 1) ; Sets main GUI always on top ;--------------------------------------------------------------- ; create the controls on the main window ;--------------------------------------------------------------- Local $okButton = GUICtrlCreateButton("OK", 160, 160, 54,24) ; create OK button GUICtrlSetOnEvent($okButton, "validateInput") ; when they click ok, call handleInputProcessRequest() GUICtrlCreateLabel("Scan Input", 10, 10) ; create a label Global $inputScan = GUICtrlCreateInput("", 10,134,358) ; create the input scan box GUICtrlSetOnEvent($inputScan, "validateInput") ; when they press enter in the scan input box, call handleInputProcessRequest() GUICtrlSetState($inputScan,$GUI_FOCUS) ; automatically sets focus on the input field GUISetState(@SW_SHOW) ; main GUI loop that runs at all times ;--------------------------------------------------------------- While 1 ;---------------------------------------------------------- ; If sumatraPDF active, resets focus back to GUI ;---------------------------------------------------------- If WinActive($pdfViewerWindowName) Then consoleWrite('While Loop sumatraPDF was active' & @CRLF) setMainWindow() ;---------------------------------------------------------- ; After data sent to ProTracker, check for mismatch ; save button to trigger the event handler when clicked ;---------------------------------------------------------- ElseIf WinActive($proTrackerWindowTitle) Then $ie = _IEAttach("ProTracker") $mismatchButton = _IEGetObjByName($ie, $proTrackerMisMatchButtonId) $oEvent = ObjEvent($mismatchButton, "mismatchButton_") If @error Then setMainWindow() ;--------------------------------------------------------------------- ; If Fusion is prompting for the case #, focus back to main GUI input ; If second GUI 'Unknown' detect do nothing ;--------------------------------------------------------------------- ElseIf WinExists($fusionWindowTitle) and WinExists($fusionCaseNumWinTitle) and Not WinActive($mainWindow) and Not WinExists('Unknown Input') Then setMainWindow() EndIF ;--------------------------------------------------------------------- ; Checks if $processFlag = Done, if so, shows PDF viewer and clears ; processFlag for next iteration ;--------------------------------------------------------------------- IF WinExists($pdfViewerWindowName) and $processFlag == 'Done' Then WinSetState ($pdfViewerWindowName, '', @SW_SHOW) $processFlag = '' setMainWindow() EndIF Sleep(100) ; Sleep to reduce CPU usage WEnd Func handleInputProcessRequest($input) $processFlag = True Local $hTimer = TimerInit() consoleWrite('> handleInputProcessRequest: ' & @CRLF) Local $idInput = identifyInput($input) ; Select a proccess to run based on id input Select Case $idInput = "container" ; regex that captures only the case number $caseTxt = StringUpper(StringRegExpReplace($strippedInputData, '\??(\w*\d*-\d*|\d*).*$','$1')) If WinExists($fusionWindowTitle) and WinExists($fusionCaseNumWinTitle) Then sendProTracker(StringUpper($strippedInputData)) sendFusion($caseTxt) ; gets pdf for sumatraPDF in seperate script, since that function is the slowest Run("viewPDF.exe " & $caseTxt) ;getSumatraPDF($caseTxt) $lastCaseNum = $caseTxt Else ; Checks to make sure the previous "Container" case num is the same ; to the current Container case num, before sending to ProTracker If($lastCaseNum <> $caseTxt) Then ; If not the same case number send alert sound SoundPlay("error.wav") Else sendProTracker($strippedInputData) EndIf EndIf Case $idInput = "user" sendProTracker($strippedInputData) Case $idInput = "cassette" sendProTracker(StringUpper($strippedInputData)) Case $idInput = "unknown" selectUnknown() EndSelect Local $fDiff = TimerDiff($hTimer) $processFlag = 'Done' consoleWrite('> handleInputProcessRequest Completed Total time: ' & $fDiff & ' ' &@CRLF&@CRLF&@CRLF) EndFunc Func sendFusion($caseTxt)     Local $hTimer = TimerInit()     consoleWrite('+ sendFusion initiated: ' & $caseTxt & @CRLF)     If $caseTxt = "" Then         MsgBox(0, "Error", "Not a valid case number")     Else         ;$fusionCaseNumWinTitle = "Case #"         $retVal1 = WinActivate($fusionCaseNumWinTitle, "")         consoleWrite("ReturnValue WinActivate " & $retVal1 & @CRLF)         $retVal2 = WinWaitActive($fusionCaseNumWinTitle,"",$winActivateTimeout)         consoleWrite("ReturnValue WinWaitActive: " & $retVal2 & @CRLF)         $retVal3 = ControlSetText($fusionCaseNumWinTitle, "", "", $caseTxt)         ;$retVal3 = ControlCommand($fusionCaseNumWinTitle, "", "", "EditPaste", $caseTxt)         consoleWrite("ReturnValue ControlSetText: " & $retVal3 & @CRLF)         ;Send($caseTxt & "{ENTER}")         WinWaitClose($fusionCaseNumWinTitle, "", $winCloseTimeout)         consoleWrite('+ sendFusion WinWaitClose: ' & @CRLF)     EndIf     Local $fDiff = TimerDiff($hTimer)     ConsoleWrite('+ sendFusion Completed Total time:' & $fDiff & ' ' & @CRLF) EndFunc
      Console logs from the SciTLE
      Window (x86) Info matches the correct handle for the WinActivate and WinWaitActivate

      Window Control (x86) Info, I've tried the CLASS, the ID, also I just noticed that the "handle" in "Control" and "Window" appear to be different as well.

       
      So far the only work-around is to close down the 3rd party application and the AutoIt script, re-open them and it works all completely fine. But this is a pain for the end-user since it's all touch screen and it slows down their workflow, which they can be extremely sensitive about.
       
    • By ozymandius257
      I'm trying to check the status of the checkbox for sharing a folder that you see when you right-click on a  folder, go to the sharing tab, then click on Advanced Sharing.

      The check box is labelled Share this folder, and looking at it using AutoIt window info, I get the following information..
      >>>> Control <<<<
      Class:    Button
      Instance:    1
      ClassnameNN:    Button1
      Name:    
      Advanced (Class):    [CLASS:Button; INSTANCE:1]
      ID:    1020
      Text:    &Share this folder
      Position:    15, 16
      Size:    306, 13
      ControlClick Coords:    57, 4
      Style:    0x50010003
      ExStyle:    0x00000004
      Handle:    0x0000000000420A52
      I'm using the following code..
      If ControlCommand("Sharing","","[CLASS:Button; INSTANCE:1]","IsChecked","") = 0 Then
          MsgBox(0, "", "not checked")
      Else
          MsgBox(0, "", "checked")
      EndIf
      But this insists the check box isn't checked when it is.  I have also tried ControlCommand("Sharing","","[ID:1020]","IsChecked","") and ControlCommand("Sharing","","Share this folder","IsChecked","") and ControlCommand("Sharing","","&Share this folder","IsChecked",""), with no joy.
       
      Any ideas?
    • By basictheprogram
      #include <Constants.au3> Func Install()    ConsoleWrite("Install EasyLog" & @LF)    Local $handle = WinWaitActive("EasyLog USB Device Driver Installer")    ConsoleWrite("Install EasyLog2 " & $handle & @LF)    Local $blah = ControlClick($handle, "", "[CLASS:Button; INSTANCE:1]", "Left", 1)    ConsoleWrite("Install EasyLog3 " & $blah & @LF)    WinClose($handle) EndFunc Install() ConsoleWrite("End of Install!" & @LF) Trying to get AutoIt to click "Install" on the EasyLogUSB Device Driver Installer window.
      Console displays:
      Install EasyLog
      Install EasyLog2 0x001B041E
      Install EasyLog3 1
      End of Install!
      Windows Info confirms the Handle is 0x001B041E

      Window Info for the Control

      For the life of me I cannot figure out why the script is not working. 
      Even $blah says the ControlClick succeeded.
      I've tried Send("{ENTER}") and MouseClick() those didn't work either.
      Any help would be appreciated.
      Thanks.
    • By AutoPM
      #RequireAdmin AutoItSetOption('MouseCoordMode', 0) If WinExists("newtitle") Then ControlClick('newtitle', '', 'Button1') EndIf a Simple script to click Button on GUI with title "newtitle". this script is working fine on my laptop on [windows 10, windows 7]
      but on a different laptop. script is not clicking this button, is there any alternative to control click then please tell. don't want to use mouseclick 
       
      Thank you
    • By tentacole
      Afternoon!
      This is my first post, so I apologize if this is in the wrong place. 
      I've created a while loop to click in a certain area of an application, and have the y axis change at the end of each loop. My loop continues to click at x:27, x:10, even though the $y is adding 15 at the end of each loop. I did a Send($x) and Send($y) into a Notepad to see if the $y had changed after each loop, and the 15 was being added to $y each loop. (If this makes sense)
       
      I'm unsure where I'm going wrong, and would be extremely grateful if someone can point me in the correct direction to fix this. 
      Local $rDirectory = "H:\oDemandProject\fList.txt" Local $rLine = _FileCountLines($rDirectory) Local $x = 27 Local $y = 10 While $rline > 0 WinActivate("OnDemand", "-> 1") WinWaitActive("OnDemand", "-> 1") ControlClick("OnDemand", "", "[CLASS:AfxFrameOrView120u; INSTANCE:1]", "left", 4, $x, $y) $y += 15 $rLine -= 1 WEnd  
×
×
  • Create New...