Key press function does not work whenever a check-box is checked or unchecked within the figure. Why?

7 views (last 30 days)
I have a figure which contains a pair of axes and few uicontrols (buttons and check-boxes). For the figure I have defined a key press callback function which enables the user to cycle through different plots and to classify these plots with keyboard shortcuts (shortcuts for the above-mentioned check-boxes). If however the check-boxes are checked or unchecked with a mouse-click, the key press function does not respond until I the user has clicked either the figure or the axis with the mouse. In the long run this gets very annoying. At first I thought I could go around this problem by bringing the figure/axes into focus with 'figure(handle2figure)' or 'axes(handle2axes)', but this did not work.
So, how can I get the key press function to work after a check-box is checked/unchecked (without the annoying figure/axes clicking)? I would really appreciate any help on this matter.
- Tuomas

Accepted Answer

Jan
Jan on 16 Nov 2012
Edited: Jan on 16 Nov 2012
According to the documentation figure(handle2figure) should transfer the focus to the figure, such that it can catch the events again. But unfortunately this does not work since Matlab 5.3 to at least 2011b (I do not have R2012 for testing). This workaround is successful under 5.3 to R2011b (and perhaps higher), but not for R2008a:
Add this to the callback of all uicontrol's:
set(HandleOfTheButton, 'enable', 'off');
drawnow;
set(HandleOfTheButton, 'enable', 'on');
Other workarounds are WindowAPI(FigH, 'SetFocus') under windows, of platform independent, but undocumented:
jPeer = get(handle(gcf), 'JavaFrame');
jPeer.getAxisComponent.requestFocus
Unfortunately there have been rumors, that JavaFrame could be removed in the future. This would invalidate hundreds of workarounds based on Java.
Please, Tuomas, send an enhancement request to TMW and ask the technical support for a reliable workaround. It is very strange and to typical of TMW, that such a fundamental problem has not been fixed for over a decade. There more voices TMW hears, the more likely this will be fixed in R2013 or R2014.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!