hariajay Posted March 13, 2009 Share Posted March 13, 2009 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 More sharing options...
Authenticity Posted March 13, 2009 Share Posted March 13, 2009 (edited) 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 March 13, 2009 by Authenticity Link to comment Share on other sites More sharing options...
hariajay Posted March 16, 2009 Author Share Posted March 16, 2009 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 More sharing options...
Authenticity Posted March 16, 2009 Share Posted March 16, 2009 (edited) 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 March 16, 2009 by Authenticity Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now