Matlab R2017b looses focus from figure window, when using WindowKeyPressFcn to activate zoom function

3 Ansichten (letzte 30 Tage)
In Matlab R2017b on Windows 10, calling the zoom function programatically, causes the figure window to loose focus, and keyboard input is directed to the Command Window from then on.
I did see this discussion, but it does not help, since I want to keep the WindowKeyPressFcn for the figure window: https://se.mathworks.com/matlabcentral/answers/385499-in-matlab-r2017a-how-do-i-change-the-focus-of-the-windowkeypressfcn-figure-callback-function-from
Any suggestions for how to work around this? Is the issue fixed in a newer version of Matlab?
See code example below. Thank you.
% Figure window focus is lost when calling 'zoom' command through keyboard
% shortcut 'z', and input is routed to command window.
% From here on, all keyboard input is useless and continues to route to
% command window.
function KeyPressZoomTest()
hFig = figure;
axes(hFig);
plot(1:10);
hFig.WindowKeyPressFcn = {@testKeyPressFcn};
end
function testKeyPressFcn(~,e)
switch e.Key
case 'z'
zoom;
end
end
  1 Kommentar
Christian Toft
Christian Toft am 17 Jul. 2018
PS. I am building a GUI programatically, where I prefer that the toolbar is hidden and does not take up space - so, simply clicking the zoom tool icon instead, is an option I would like to avoid. Thank you.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 17 Jul. 2018
This is still an issue through R2018a. I would tend to doubt it will change any time soon, but perhaps I will be surprised.
For work arounds, you need to consult undocumentedmatlab.com . The workaround that I documented only works up to R2014a, but Yair found a way for R2014b and later.

Weitere Antworten (0)

Kategorien

Mehr zu Graphics Objects finden Sie in Help Center und File Exchange

Produkte


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by