How to find out, which of the gadgets is activated?

Just starting out? Need help? Post your questions and find answers here.
high key
User
User
Posts: 23
Joined: Sun Jun 08, 2003 8:07 pm

How to find out, which of the gadgets is activated?

Post by high key »

I need to know, which one of several gadgets is activated.
Setting the focus to a gadget is easy with activategadget(#),
but I didn't find a function, to GET the number of the active gadget (which could have changed since the last activategadget)
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

Heya high key,

When I need something like this I set a var at time of activating, eg, curActiveGadget = #_whatever
@}--`--,-- A rose by any other name ..
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

You can try the GetFocus_() API on Windows and compare its result with GadgetID(YourGadget).
high key
User
User
Posts: 23
Joined: Sun Jun 08, 2003 8:07 pm

Simple solution

Post by high key »

I found out a simple solution for myself *g*

to test, if gadget(x) is activated, I now use the following lines

thefocusishere=getfocus_()

if gadgetid(gadget(x)) = thefocusishere
; gadget(x) has the focus!
endif
high key
User
User
Posts: 23
Joined: Sun Jun 08, 2003 8:07 pm

@ Fred

Post by high key »

You were first ;-))

Thanks :-)
high key
User
User
Posts: 23
Joined: Sun Jun 08, 2003 8:07 pm

and I had an error

Post by high key »

if gadgetid(x) =...
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

:lol:
RichardL
Enthusiast
Enthusiast
Posts: 532
Joined: Sat Sep 11, 2004 11:54 am
Location: UK

Post by RichardL »

Does this method work with ComboBoxGadget?

I make a ComboBox thus:

Code: Select all

ComboBoxGadget(3,Gx+5,Gy+15,100,200,#PB_ComboBox_Editable )
And set up a hot key:

Code: Select all

AddKeyboardShortcut(1, #PB_Shortcut_Return ,504)
And then try to detect if the user has pressed RETURN on it in the #PB_EventMenu handler:

Code: Select all

        Case 504  ; Hot key 'RETURN'
          Debug GetFocus_()
          Debug GadgetID(3)
          
          If GetFocus_() = GadgetID(3)
           MyBeep(1000,100) 
          EndIf

No beeps!
The two debug values look 'real'... but are different :(
RichardL
Enthusiast
Enthusiast
Posts: 532
Joined: Sat Sep 11, 2004 11:54 am
Location: UK

Post by RichardL »

OK, found it by searching this site... it seems the ComboBox is a special case.

Code: Select all

 
       Case 504  ; Hot key 'RETURN'
          If GetFocus_() = GetWindow_(GadgetID(3), #GW_CHILD)
            MyBeep(1000,100) 
          EndIf
As my mother used to say...

"None so blind as those who do not look in the right place!"
Post Reply