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.
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에서 Environment and Settings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!