Re-enable keypress capture in pan or zoom mode
13 次查看(过去 30 天)
显示 更早的评论
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
2015-10-27
That is correct code for earlier versions.
We do not know a solution for current versions. UndocumentedMatlab might know
采纳的回答
更多回答(1 个)
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1189153/image.png)
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!