Jump to content
Sign in to follow this  
hariajay

Find out which button is clicked

Recommended Posts

hariajay

Hi,

Am new to AutoIt. Need help to find out which button is clicked during automation. For instance, there is a NEXT and CANCEL button on screen. I use a ControlClick on NEXT to automate an installation. But, if I click on CANCEL how do I find out that the user has clicked on CANCEL instead?

Any help would be appreciated.

Thanks.

Share this post


Link to post
Share on other sites
Authenticity

A silly example, I don't know why ControlCommand($hWnd, '', 'Button3', 'IsChecked', '') doesn't return 1 if a button is clicked and of-course is visible and focused:

#include <GuiButton.au3>

Run('control sysdm.cpl')
WinWaitActive('System Properties')
Dim $hWnd = WinGetHandle('System Properties')

Dim $hCancel = ControlGetHandle($hWnd, 'Cancel', 2)
Dim $hOK = ControlGetHandle($hWnd, 'OK', 1)

While 1
    If _GUICtrlButton_GetState($hCancel) = 620 Then
        _GUICtrlButton_Click($hCancel)
        _Cancel()
        ExitLoop
    EndIf
    
    If _GUICtrlButton_GetState($hOK) = 620 Then
        _GUICtrlButton_Click($hOK)
        _OK()
        ExitLoop
    EndIf
    
    Sleep(20)
WEnd
    
Func _Cancel()
    MsgBox(0x40, 'Cancel', 'You''ve pressed "Cancel" button')
EndFunc

Func _OK()
    MsgBox(0x40, 'Cancel', 'You''ve pressed "OK" button')
EndFunc
Edited by Authenticity

Share this post


Link to post
Share on other sites
hariajay

A silly example, I don't know why ControlCommand($hWnd, '', 'Button3', 'IsChecked', '') doesn't return 1 if a button is clicked and of-course is visible and focused:

#include <GuiButton.au3>

Run('control sysdm.cpl')
WinWaitActive('System Properties')
Dim $hWnd = WinGetHandle('System Properties')

Dim $hCancel = ControlGetHandle($hWnd, 'Cancel', 2)
Dim $hOK = ControlGetHandle($hWnd, 'OK', 1)

While 1
    If _GUICtrlButton_GetState($hCancel) = 620 Then
        _GUICtrlButton_Click($hCancel)
        _Cancel()
        ExitLoop
    EndIf
    
    If _GUICtrlButton_GetState($hOK) = 620 Then
        _GUICtrlButton_Click($hOK)
        _OK()
        ExitLoop
    EndIf
    
    Sleep(20)
WEnd
    
Func _Cancel()
    MsgBox(0x40, 'Cancel', 'You''ve pressed "Cancel" button')
EndFunc

Func _OK()
    MsgBox(0x40, 'Cancel', 'You''ve pressed "OK" button')
EndFunc

Thanks for the reply. This helps a lot. Could you please tell me what the number 620 means in this line?

If _GUICtrlButton_GetState($hCancel) = 620

Share this post


Link to post
Share on other sites
Authenticity

I've just output to the console what _GuiCtrlButton_GetState return when I'm hovering a button, or clicking it or clicking but releasing outside the button's border and 620 is what I've got when the button was clicked.

Edited by Authenticity

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.