how to detect [ESC] key press
30 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(2 个)
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 个评论
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Web Services 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!