how to detect [ESC] key press

조회 수: 31 (최근 30일)
saadani seifeddine
saadani seifeddine 2015년 10월 10일
댓글: Josep Llobet 2022년 3월 14일
function KeyPressFcn(~, evnt)
global h
h.fig.CurrentCharacter
%or% evnt.Key
whit this code I can detect all keyboard keys except escape key! any suggestion?

답변 (2개)

Geoff Hayes
Geoff Hayes 2015년 10월 10일
Saadani - have you tried the following? Just save the below code to an m file called KeyPressFcnTest and run it. I was able to observe the escape key event while running this code on OS X 10.9.5 with R2014a.
function KeyPressFcnTest
close all;
h = figure;
set(h,'WindowKeyPressFcn',@KeyPressFcn);
function KeyPressFcn(~,evnt)
fprintf('key event is: %s\n',evnt.Key);
end
end
  댓글 수: 3
Geoff Hayes
Geoff Hayes 2015년 10월 10일
So nothing happens when you press the escape key?
Josep Llobet
Josep Llobet 2022년 3월 14일
This is so great

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


Allan Kjærgaard Jensen
Allan Kjærgaard Jensen 2018년 4월 17일
function myGUI_WindowKeyPressFcn(hObject, eventdata, handles)
switch eventdata.Key case '1' disp('Pressed key 1'); case '2' disp('Pressed key 2'); case 'escape' disp('Pressed ESC-key'); end

카테고리

Help CenterFile Exchange에서 Web Services에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by