Page 1 of 1
How to find out, which of the gadgets is activated?
Posted: Thu Aug 18, 2005 11:14 am
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)
Posted: Thu Aug 18, 2005 1:55 pm
by Dare2
Heya high key,
When I need something like this I set a var at time of activating, eg, curActiveGadget = #_whatever
Posted: Thu Aug 18, 2005 3:03 pm
by Fred
You can try the GetFocus_() API on Windows and compare its result with GadgetID(YourGadget).
Simple solution
Posted: Thu Aug 18, 2005 3:03 pm
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
@ Fred
Posted: Thu Aug 18, 2005 3:05 pm
by high key
You were first

)
Thanks

and I had an error
Posted: Thu Aug 18, 2005 3:08 pm
by high key
if gadgetid(x) =...
Posted: Thu Aug 18, 2005 3:39 pm
by Fred
Posted: Fri Sep 02, 2005 9:56 am
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

Posted: Fri Sep 02, 2005 11:06 am
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!"