Click escape to stop my MouseDownfcn in the GUI?
조회 수: 2 (최근 30일)
이전 댓글 표시
When you select the "move" button, my GUI sees if the cursor is on my axes and when you press it, you can move the graph in it. What I want is that when the escape button is pressed, the graphic cannot be moved. That is, I want to disable this function but when the button is pressed again it will work again.
Here is the pushbutton
function move_Callback(hObject, eventdata, handles)
% hObject handle to mover_mano (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
hold(handles.oxi_Plot,'on');
linkaxes([handles.oxi_Plot handles.TOI_Plot],'x');
if hObject.Value == 1
set(handles.figure1, ...
'WindowButtonDownFcn', @mouseDownCallback, ...
'WindowButtonUpFcn', @mouseUpCallback, ...
'WindowButtonMotionFcn', @mouseMotionCallback);
end
Here is where I want to write the code when escape function is pressed
function figure1_WindowKeyPressFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata structure with the following fields (see MATLAB.UI.FIGURE)
% Key: name of the key that was pressed, in lower case
% Character: character interpretation of the key(s) that was pressed
% Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed
% handles structure with handles and user data (see GUIDATA)
switch eventdata.Key
case 'escape'
disp('Pressed ESC-key');
end
댓글 수: 0
답변 (1개)
Guillaume
2020년 1월 10일
Probably, the simplest thing is to disable whichever callback you don't want to execute once escape is pressed, so in the WindowKeyPressFcn:
switch eventdata.Key
case 'escape'
set(handles.figure1, 'WindowButtonMotionFcn', []); %disable motion callback
Of course, you'll need to set it back once you want it to be enabled again.
Another option is to add a flag to your handles structure that you set/unset on escape and check for in the callback:
%handles.domove is a flag that you created on GUI construction
%in WindowKeyPressFcn
switch eventdata.Key
case 'escape'
set(handles.domove, false); %disable motion callback
guidata(hObject, handles); %don't forget to save handles
%in callback that can be enabled/disabled, e.g WindowButtonMotionFcn
if handles.domove
%normal code
end %else do nothing
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!