Jump to content

How to simulate Clicks on an Inactive Window


Recommended Posts

Hello,

I managed to get a basic script working that logs into the erp system, runs a stored procedure with parameters etc and waits for the results.
Now I'm facing a problem of how to trigger the last action, which is to execute export into excel.
In the erp's gui, this is done by a dedicated toolbar, that is not accessible by any shortcut key (I did read the accompanying docs), cannot be reached by Tab etc.
I have to click the "Actions" listbox and then one of the list options (Export to Excel) = click Actions, wait, click Export to Excel option from the scroll-down.

image.png.c7e5fd1e631ff1721181bbbe955c4ae8.png

I can do it using the click commands, but they only work on active window and I need this to run on server.
I tried ControlClick with the correct windows handle and without controlId (with various x,y coordinates) without success. To minimise the risk on not providing the right x,y coordinates, I put them into double for-to loops, incrementing each 1-500 with some delays... again no result, not a single successfull click. 

Furthermore a custom function recommended elsewhere (_MouseClickPlus) also did not work.
I even tried to list ALL the window controls (cca 100) and manually send their controlId to the ControlClick method.
It clicked all aroung the gui except this very toolbar. 

This is what the info tool provides reg. the toolbar: (another "fun" thing is that the controlIDs change with each instance)
image.png.c1699ce1c93923d11bcf9f2769c6118f.png


In this situation, is there anything you would advise me to do?
Is there perhaps another function worth trying, or try autohotkey or some other scripting tool for this singular purpose?

Thank you,
Daniel

Edited by DanMeow
typo
Link to comment
Share on other sites

I don't have any control handle that would operate this tollbar with the ControlClick (I tried all window control handles manually).
But I guess I could try another control's (completely different in the gui but working with the method) and provide the correct coordinates.
I will report back how it went. Thank you.

Link to comment
Share on other sites

Here an example with Window Explorer how to use the toolbar handle to click a specific area :

;Run ("explorer")
;Sleep(500)

Local $hWnd = WinActivate("[CLASS:CabinetWClass]")
;MsgBox ($MB_SYSTEMMODAL,"",$hWnd)

Local $hCtrl = ControlGetHandle($hWnd,"","ToolbarWindow321")
;MsgBox ($MB_SYSTEMMODAL,"",$hCtrl)
Local $aPos = ControlGetPos ($hWnd, "", $hCtrl)
_ArrayDisplay ($aPos)
ControlClick ($hWnd, "", $hCtrl, "left", 1, $aPos[0]+$aPos[2]/3, $aPos[1]+$aPos[3]/2)

Use the CLASSNN to get the handle of the control

Edited by Nine
Link to comment
Share on other sites

Oh man, you helped me so much!
This works for the 1st click ("Actions"):

Local $hCtrl = ControlGetHandle($hWnd,"","[NAME:_BrowseToolbar_Toolbars_Dock_Area_Top]")
ControlClick($hWnd, "", $hCtrl, "left", 1, 46, 17)

Now my challenge will be the 2nd click, where the control is not named (and ID's keep changing).
But the fact the instance of the class is 1 looks good. Maybe at least this will remain the same...


image.thumb.png.bca82ee5b3e9a7009de384585a01b2ab.png

TY again!

Link to comment
Share on other sites

got it! 
... and it's a new window (class 808 vs 8, missed it completely at first) 
This works (tested while disconnected from rdc and at different gui positions and sizes)

$hWnd = WinGetHandle("prod: 200 ... [CZK] (1) - QAD Enterprise Applications")
Local $hCtrl = ControlGetHandle($hWnd,"","[NAME:_BrowseToolbar_Toolbars_Dock_Area_Top]")
ControlClick($hWnd, "", $hCtrl, "left", 1, 46, 17)
Sleep(1500)
$hWnd2 = WinGetHandle("[Class:WindowsForms10.Window.808.app.0.2004eee]")
Local $hCtrl2 = ControlGetHandle($hWnd2,"","[Classnn:WindowsForms10.Window.8.app.0.2004eee1]")
ControlClick($hWnd, "", $hCtrl2, "left", 1, 14, 86)

Perfect, TY!

Link to comment
Share on other sites

  • 3 years later...

Hi guys, I am facing the same issue with a script for Teradata SQL. I need the script to open a connection and to do so it must be able to click on the area I marked in red.

Even the debug mode isn't helping because it says that everything is executed successfully but the new window is not opening. 

A copy of my script:

ConsoleWrite("Waiting for Teradata SQL Assistant window..." & @CRLF)
Local $hWnd = WinWait("Teradata SQL Assistant", "", 10)

; Check if the window handle was obtained successfully
If $hWnd Then
    ConsoleWrite("Teradata SQL Assistant window found." & @CRLF)

    ; Get the handle of the main window
    $hWnd = WinGetHandle("Teradata SQL Assistant")

    ; Check if the main window handle is valid
    If $hWnd Then
        ConsoleWrite("Activating Teradata SQL Assistant window..." & @CRLF)
        ; Activate the Teradata SQL Assistant window
        WinActivate($hWnd)
        WinWaitActive($hWnd)

        ; Find and click the toolbar area to start a connection
        ConsoleWrite("Finding toolbar area..." & @CRLF)
        Local $hToolbar = ControlGetHandle($hWnd, "", "[NAME:_MainWnd_Toolbars_Dock_Area_Top]")

        ; Check if the toolbar control handle was obtained successfully
        If $hToolbar Then
            ConsoleWrite("Toolbar area found. Clicking..." & @CRLF)
            ; Click on the toolbar area (adjust the coordinates as needed)
            ControlClick($hWnd, "", $hToolbar, "left", 1, 25, 65)
        Else
            ConsoleWrite("Error: Failed to find the toolbar area." & @CRLF)
            MsgBox(16, "Error", "Failed to find the toolbar area.")
        EndIf
    Else
        ConsoleWrite("Error: Failed to get the handle of the main window." & @CRLF)
        MsgBox(16, "Error", "Failed to get the handle of the main window.")
    EndIf
Else
    ConsoleWrite("Error: Teradata SQL Assistant window not found." & @CRLF)
    MsgBox(16, "Error", "Teradata SQL Assistant window not found.")
EndIf
 

 

Teradata.png

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