Borrar filtros
Borrar filtros

Re-enable keypress capture in pan or zoom mode

11 visualizaciones (últimos 30 días)
Daniel Lyddy
Daniel Lyddy el 27 de Oct. de 2015
Editada: Brunno Machado de Campos el 11 de Nov. de 2022
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 comentario
Walter Roberson
Walter Roberson el 27 de Oct. de 2015
That is correct code for earlier versions.
We do not know a solution for current versions. UndocumentedMatlab might know

Iniciar sesión para comentar.

Respuesta aceptada

Yair Altman
Yair Altman el 28 de Oct. de 2015
  2 comentarios
Walter Roberson
Walter Roberson el 28 de Oct. de 2015
Thanks, Yair.
Daniel Lyddy
Daniel Lyddy el 28 de Oct. de 2015
Editada: Daniel Lyddy el 28 de Oct. de 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).

Iniciar sesión para comentar.

Más respuestas (1)

Brunno Machado de Campos
Brunno Machado de Campos el 11 de Nov. de 2022
Editada: Brunno Machado de Campos el 11 de Nov. de 2022
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

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by