|
"Matt Fig" <spamanon@yahoo.com> wrote in message <gk5o7a$kap$1@fred.mathworks.com>...
> "Jiro Doke" <jiro.doke@mathworks.com> wrote in message
> > You should set the WindowKeyPressFcn property of the figure. This gets called even if other components in your figure have focus.
> >
> >
> > jiro
>
> My version of Matlab doesn't have this as a property for figures. I think this may not always work anyway, depending on the components of the GUI and what the keypressfcn does. For example, if you have an edit box that has a callback which does something similar to what the figure's keypressfcn does, but lets you specify a value, will the windowkeypressfcn execute for every value entered into the edit box? Even when you press return?
>
> The way I was thinking about would be simple enough:
>
> ch = get(gcf,'chi'); % Get all the children.
> ch = ch(strcmp(get(ch(:),'type'),'uicontrol')) % Take only uicontrols
> ch = ch(strcmp(get(ch(:),'style'),'pushbutton')) % Take only pushbuttons
> set(ch,'keypressfcn',{@func}) % set their keypressfcn to the same as that of fig.
>
> Note by changing the filtering operations above (lines 2 and 3), one could choose to set the keypressfcn for any children of the figure desired.
>
> Just a thought.
Yes, WindowKeyPressFcn would get called regardless of which control is in focus. You could do a check in the function to see if the component with focus is an edit box or not, but what you proposed should be fine as well. BTW, you can also use findobj to find the handles:
ch = findobj(figH, 'type', 'uicontrol', 'style', 'pushbutton');
jiro
|