Sign in to follow this  
Followers 0
simpleraison

How to check if a button is active (not greyed out) before continuing?

11 posts in this topic

Hey guys is there any code which will help me check either if a button comes out of being greyed out whilst doing a process before continuing with the remaining commands?

I could do it vice versa on the other hand and wait for a button to become not active before proceeding too!

Thanks guys. :-)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

GuiCtrlGetState()

See help file.

:graduated:

Edit: As Zedna said, ControlCommand() makes more sense if it's not your own script's GUI.

:(

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

If button is in other application then use

ControlCommand() with 'IsEnabled' command

Dude here is the code i am currently using but it seems as if it doesnt do anything?? :-(

$isvisible = ControlCommand ( "Slow Commenter", "", "[CLASS:Button; INSTANCE:2]", "IsEnabled")
WinWaitActive($isvisible, "", 1000000000000000000000000000)

Share this post


Link to post
Share on other sites

GuiCtrlGetState()

See help file.

:graduated:

Dude considering the code i posted above how could i implement GuiCtrlGetState() into it? Sorry im real new to AutoIT! And so far only used primitive functions not delved into anything to deep! :-)

Share this post


Link to post
Share on other sites

Dude here is the code i am currently using but it seems as if it doesnt do anything?? :-(

$isvisible = ControlCommand ( "Slow Commenter", "", "[CLASS:Button; INSTANCE:2]", "IsEnabled")
WinWaitActive($isvisible, "", 1000000000000000000000000000)

While ControlCommand("Slow Commenter", "", "Button2","IsEnabled","") = 0
 Sleep(50)
WEnd
MsgBox(0,'','Now it is enabled.')

Share this post


Link to post
Share on other sites

While ControlCommand("Slow Commenter", "", "Button2","IsEnabled","") = 0
 Sleep(50)
WEnd
MsgBox(0,'','Now it is enabled.')

Zedna this is the code i just tried but no joy at all, any more ideas! :-(

While ControlCommand("Slow Commenter", "", "[CLASS:Button2; INSTANCE:2]", "IsEnabled","") = 0
    Sleep(50)
WEnd MsgBox(0,'','Now it is enabled.')

Share this post


Link to post
Share on other sites

I think the code should be

"[CLASS:Button; INSTANCE:2]"
or
"Button2"
Also, I think that the final MsgBox should be on the line after the WEnd statement.

You can also try this

While 1
    Select
        Case Not WinExists("Slow Commenter", "")
            _Status("ERROR", "Window 'Slow Commenter' is not Visible", 2)
        Case Not ControlCommand("Slow Commenter", "", "[CLASS:Button; INSTANCE:2]", "IsVisible", "")
            _Status("ERROR", "Button2 is not Visible", 2)
        Case ControlCommand("Slow Commenter", "", "[CLASS:Button; INSTANCE:2]", "IsEnabled", "")
            _Status("Success", "Button2 is Enabled" & @LF & "Button2 is named " & ControlGetText("Slow Commenter", "", "[CLASS:Button; INSTANCE:2]"))
            Exit
        Case Not ControlCommand("Slow Commenter", "", "[CLASS:Button; INSTANCE:2]", "IsEnabled", "")
            _Status("ERROR", "Button2 is not enabled yet", 2)
    EndSelect
WEnd

Func _Status($Title = "", $Text = "", $TimeOut = 0)
    MsgBox(0, $Title, $Text, $TimeOut)
EndFunc   ;==>_Status

Share this post


Link to post
Share on other sites

I think the code should be

"[CLASS:Button; INSTANCE:2]"
or
"Button2"
Also, I think that the final MsgBox should be on the line after the WEnd statement.

You can also try this

While 1
    Select
        Case Not WinExists("Slow Commenter", "")
            _Status("ERROR", "Window 'Slow Commenter' is not Visible", 2)
        Case Not ControlCommand("Slow Commenter", "", "[CLASS:Button; INSTANCE:2]", "IsVisible", "")
            _Status("ERROR", "Button2 is not Visible", 2)
        Case ControlCommand("Slow Commenter", "", "[CLASS:Button; INSTANCE:2]", "IsEnabled", "")
            _Status("Success", "Button2 is Enabled" & @LF & "Button2 is named " & ControlGetText("Slow Commenter", "", "[CLASS:Button; INSTANCE:2]"))
            Exit
        Case Not ControlCommand("Slow Commenter", "", "[CLASS:Button; INSTANCE:2]", "IsEnabled", "")
            _Status("ERROR", "Button2 is not enabled yet", 2)
    EndSelect
WEnd

Func _Status($Title = "", $Text = "", $TimeOut = 0)
    MsgBox(0, $Title, $Text, $TimeOut)
EndFunc   ;==>_Status

Varian thanks for the help so i added this code into the script all i get when the process is running and the button is greyed out is '_Status("ERROR", "Button2 is not enabled yet", 2)' and then the message box stays there whislt the process carries on running in the background and then i see the process finish in the background and the button become active and then nothing? I pressed ok in the message box but still nothing? Any ideas?

Share this post


Link to post
Share on other sites

Varian thanks for the help so i added this code into the script all i get when the process is running and the button is greyed out is '_Status("ERROR", "Button2 is not enabled yet", 2)' and then the message box stays there whislt the process carries on running in the background and then i see the process finish in the background and the button become active and then nothing? I pressed ok in the message box but still nothing? Any ideas?

Where is "Button2"...on what screen? What is the Button Text?..I will try to recreate the problem on my end

Share this post


Link to post
Share on other sites

Where is "Button2"...on what screen? What is the Button Text?..I will try to recreate the problem on my end

The button appears on a window which appears on top of the original application. And the text in the button is 'Close' The button is located in the window in the bottom right! Hope that helps let me know if you need any more information.

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  
Followers 0