How to get status of a button in a window

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
Trader AP
Posts: 3
Joined: 04 Jun 2023, 09:22

How to get status of a button in a window

Post by Trader AP » 04 Jun 2023, 13:48

I have a window where I have clicked a button. The processing time of the action behind this button is variable (from a few seconds to a few minutes depending on the data its dealing with). I want to check the status of the button from when it reverts from "greyed out" back to being in a state where it can be pressed again. How can I do this?. I am assuming I have to use the GuiControl calls but would be grateful if someone could point me to some code fragments as to how to get the HWND of the window button and then how to check its state. Thanks.

User avatar
mikeyww
Posts: 26602
Joined: 09 Sep 2014, 18:38

Re: How to get status of a button in a window

Post by mikeyww » 04 Jun 2023, 14:14

Welcome to this AutoHotkey forum!

How about :arrow: ControlGetEnabled?

Trader AP
Posts: 3
Joined: 04 Jun 2023, 09:22

Re: How to get status of a button in a window

Post by Trader AP » 04 Jun 2023, 15:01

I wrote a little code as follows

Code: Select all

Hwnd := WinExist("Historical Data")

if Hwnd {
    IsEnabled := ControlGetEnabled(Hwnd)

    OutputDebug "For " Hwnd " ControlGetEnabled is " IsEnabled "`n"

    Controls := WinGetControls("Historical Data")

    OutputDebug "Array Length is " Controls.length "`n"

    for n in Controls
        OutputDebug "Controls are " n "`n"
}
else {
    OutputDebug "No Hwnd `n"
}
Debug returns

For 659106 ControlGetEnabled is 1
Array Length is 0

The number 659106 is the same as Window Spy so its getting the correct window, but the array of controls being returned is 0.

Does that mean I cannot access the button status on this window?

Trader AP
Posts: 3
Joined: 04 Jun 2023, 09:22

Re: How to get status of a button in a window

Post by Trader AP » 04 Jun 2023, 15:18

My amended test harness is as follows:

Code: Select all

WindowName := "Historical Data"

Hwnd := WinExist(WindowName)

if Hwnd {

    OutputDebug "For " WindowName ", the Hwnd is " Hwnd " and ControlGetEnabled is " ControlGetEnabled(Hwnd) "`n"

    Controls := WinGetControls(WindowName)

    OutputDebug "The Controls array length is " Controls.length "`n"

    for n in Controls
        OutputDebug "Controls are " n "`n"
}
else {
    OutputDebug "For " WindowName ", no Hwnd found`n"
}
It returns

For Historical Data, the Hwnd is 659106 and ControlGetEnabled is 1
The Controls array length is 0

Does this mean there are no controls that can be accessed by AutoHotKey.

(BTW, If I run this test harness on Notepad or Windows Explorer I do get names of controls)

User avatar
mikeyww
Posts: 26602
Joined: 09 Sep 2014, 18:38

Re: How to get status of a button in a window

Post by mikeyww » 04 Jun 2023, 16:06

It is possible. An alternative could be UI Automation, detailed on the forum.

Post Reply

Return to “Ask for Help (v2)”