Jump to content

Find out which button is clicked


Recommended Posts

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

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