MATLAB Answers

Re-enable keypress capture in pan or zoom mode

35 views (last 30 days)
Daniel Lyddy
Daniel Lyddy on 27 Oct 2015
Edited: Daniel Lyddy on 28 Oct 2015
I'm running R2014b, and I inherited some pre-2014b code that used an undocumented feature to re-enable capture of keypress events in either pan or zoom mode:
% This fix re-enables capture of in-window keypresses in pan or zoom mode. It
% makes use of an undocumented MATLAB feature that is broken in R2014b. I am
% still looking for the correct way to do this in R2014b or later.
function window_keypress_panzoom_fix()
if verLessThan('matlab', '8.4')
hManager = uigetmodemanager(figure_handle);
set(hManager.WindowListenerHandles, 'Enable', 'off');
set(figure_handle, 'WindowKeyPressFcn', []);
set(figure_handle, 'KeyPressFcn', @(obj, evt) keypress_cb(obj, evt));
end
end
In R2014b, and maybe earlier, it seems that this fix has been broken by the fact that hManager.WindowListenerHandles, which is an object of class event.proplistener, no longer has any 'set' methods (I think all its properties are now protected).
For R2014b or later, how do I re-enable keypress capture in pan or zoom mode?

  1 Comment

Walter Roberson
Walter Roberson on 27 Oct 2015
That is correct code for earlier versions.
We do not know a solution for current versions. UndocumentedMatlab might know

Sign in to comment.

Accepted Answer

Yair Altman
Yair Altman on 28 Oct 2015

  2 Comments

Daniel Lyddy
Daniel Lyddy on 28 Oct 2015
This comment is directed toward Yair's answer, above. The fix he lays out in that link worked for me. For completeness, here is what my new function looks like:
% This fix re-enables capture of in-window keypresses in pan or zoom mode.
% It makes use of an undocumented MATLAB feature that was changed in R2014b.
% This approach may even work in datatip mode; but I haven't tested that. It
% is based on Yair Altman's writeup on the following webpage. (DJL)
%
% http://undocumentedmatlab.com/blog/enabling-user-callbacks-during-zoom-pan
function window_keypress_panzoom_fix()
% FIXME - uigetmodemanager is undocumented (DJL)
hManager = uigetmodemanager(figure_handle);
try
% this should work for versions of MATLAB <= R2014a
set(hManager.WindowListenerHandles, 'Enable', 'off');
catch
% this works in R2014b, and maybe beyond; your mileage may vary
[hManager.WindowListenerHandles.Enabled] = deal(false);
end
% these lines are common to all versions up to R2014b (and maybe beyond)
set(figure_handle, 'WindowKeyPressFcn', []);
set(figure_handle, 'KeyPressFcn', @(obj, evt) keypress_cb(obj, evt));
end
I've tested this in R2014b ... and there was much rejoicing (yay).

Sign in to comment.

More Answers (0)

Sign in to answer this question.