Sign in to follow this  
Followers 0
timjohnson

test if user click "button X"

5 posts in this topic

Hi all,

How can I test if the user click a certain button.

Say if the user click the "cancel" button during the print diaglog box, I want to do action X.

So, how can I test if the perdorm a certain muose click on that "cancel" button?

Many thanks.

Share this post


Link to post
Share on other sites



If this is a GUI you've made:

While 1
    $Msg = GUIGetMsg()
    If $Msg = $GUI_EVENT_CLOSE Then
       ; Do something
    EndIf
Wend

If your not using those, then maybe take a look at WinGetState(), Maybe MouseGetPos() and a mixture of _IsPressed(). Maybe there is some other means that I'm just a bit brain dead to think of at the moment.

GL!


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Cheers, exactly what I need. Many many thanks.

If this is a GUI you've made:

While 1
    $Msg = GUIGetMsg()
    If $Msg = $GUI_EVENT_CLOSE Then
      ; Do something
    EndIf
Wend

If your not using those, then maybe take a look at WinGetState(), Maybe MouseGetPos() and a mixture of _IsPressed(). Maybe there is some other means that I'm just a bit brain dead to think of at the moment.

GL!

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Hi all,

How can I test if the user click a certain button.

Say if the user click the "cancel" button during the print diaglog box, I want to do action X.

So, how can I test if the perdorm a certain muose click on that "cancel" button?

Many thanks.

it kind of depends on where the button is... if it's a response to a msgbox, you check that by assigning the result to a variable:

$LikeThis = msgbox(3,"Wasn't This Easy?","Don't you love the helpfile?")
select
case $LikeThis = 6
msgbox(0,"Good.","Me too.")
case $LikeThis = 7
msgbox(0,"Oh yeah?!","You should read it before you answer")
case $LikeThis = 2
msgbox(0,"Hmmm.","Well i guess cancel is better than no...")
EndSelect

if you're trying to get a response from a button in a gui you've made, then it depends on how your gui is running, either as a message loop, or eventmode. either way you should assign the button to a variable so that the return value can be evaluated.

;either way you run gui, next line should be the same.  it assigns the button a name, so messages can be received from the button via the variable
$ThisButton = GUICtrlCreateButton("Click me.  I dare you.",0,0)
;for message loop (default) gui:
;... other code here
$msg = GUIGetMsg()
Select
Case $msg = $ThisButton
    MsgBox(0,"Uh-oh","You've done it now...")
EndSelect
;... other code

;for OnEventMode (my fav)
GUICtrlSetOnEvent($ThisButton,"BTN")
Func BTN()
    MsgBox(0,"Uh-oh","You've done it now...")
EndFunc

if you're talking about other buttons, like buttons in gui's you didn't make, or buttons to close the window, let me know and i'll provide more examples....

***edit*** too slow i guess....

Edited by cameronsdad

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

if you're talking about other buttons, like buttons in gui's you didn't make, or buttons to close the window, let me know and i'll provide more examples....

***edit*** too slow i guess....

Hi cameronsdad,

Thanks for your help. I have tried WinGetState(). I thought I make it works, but in fact it didn't.

For the buttons, it is in fact buttons didn't make by me. It is just the Print" and "Cancel" buttons in the standard print diaglogue box

What I try to do is if the user click "Print"... of course it print stuff,

else if user click "cancel", I will do a bunch of other action.

Thanks.

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