Re-enable keypress capture in pan or zoom mode

조회 수: 13 (최근 30일)
Daniel Lyddy
Daniel Lyddy 2015년 10월 27일
편집: Brunno Machado de Campos 2022년 11월 11일
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
Walter Roberson
Walter Roberson 2015년 10월 27일
That is correct code for earlier versions.
We do not know a solution for current versions. UndocumentedMatlab might know

댓글을 달려면 로그인하십시오.

채택된 답변

Yair Altman
Yair Altman 2015년 10월 28일
  댓글 수: 2
Walter Roberson
Walter Roberson 2015년 10월 28일
Thanks, Yair.
Daniel Lyddy
Daniel Lyddy 2015년 10월 28일
편집: Daniel Lyddy 2015년 10월 28일
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).

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Brunno Machado de Campos
Brunno Machado de Campos 2022년 11월 11일
편집: Brunno Machado de Campos 2022년 11월 11일
I will answer here to illustrate what I did.
I created an interface to interact with medical images. This interface has shortcuts with Keyboard keys. The scroll button standard function (without any key modifier) of my tool is change the image slice.
My intention was: when hold Shift Key, the Scroll Button function changes to ZOOM tools, desactivating when the key is released. The problem is that after activating the ZOOM mode, the KeyReleaseFcn is not activated and I got no callbacks to desactivate the ZOOM mode.
The solution: when oppening and creating the main figure, I added my personalized @KeyReleaseFcn to each util mode KeyReleaseFcn callback function.
MainFig = figure('Name','ResectVol_Adjust_GUI','NumberTitle','off','Color',[0 0 0],...
'Position',[ScreSize(1)*0.004 ScreSize(2)*0.044 ScreSize(1)*0.99 ScreSize(2)*0.9],...
'MenuBar','none','WindowKeyPressFcn',@KeySelectF,'KeyReleaseFcn',@KeyReleasF,...
'WindowScrollWheelFcn',@ScrollF);
handles.MainFig = MainFig;
handles.zo = zoom(handles.MainFig);
handles.zo.Enable = 'on';
handles.hManager = uigetmodemanager(handles.MainFig);
handles.hManager.CurrentMode.KeyReleaseFcn = @KeyReleasF;
handles.zo.Enable = 'off';
handles.pan = pan(handles.MainFig);
handles.pan.Enable = 'on';
handles.hManager = uigetmodemanager(handles.MainFig);
handles.hManager.CurrentMode.KeyReleaseFcn = @KeyReleasF;
handles.pan.Enable = 'off';
Then, when the ZOOM or PAN mode is activated, its also recognizes the release of the Key, deactivating the mode.
Activating the mode:
function KeySelectF(hObject,eventdata,handles)% function to recognize keyboard shortcuts
handles = guidata(hObject);
if isequal(eventdata.Modifier{1},'shift')
handles.zo.Enable = 'on';
handles.output = hObject;
guidata(hObject, handles);
end
if isequal(eventdata.Modifier{1},'alt')
handles.pan.Enable = 'on';
handles.output = hObject;
guidata(hObject, handles);
end
end
The KeyReleaseFcn:
function KeyReleasF(hObject,eventdata,handles)
handles = guidata(hObject);
handles.zo.Enable = 'off';
handles.pan.Enable = 'off';
handles.output = hObject;
guidata(hObject, handles);
end

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by