how to detect [ESC] key press

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?

Respuestas (2)

Geoff Hayes
Geoff Hayes el 10 de Oct. de 2015

1 voto

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 comentarios

saadani seifeddine
saadani seifeddine el 10 de Oct. de 2015
but I run Matlab R2015a on Windows 7x64 the same code work with all keys except [ESC] key!!!
Geoff Hayes
Geoff Hayes el 10 de Oct. de 2015
So nothing happens when you press the escape key?
Josep Llobet
Josep Llobet el 14 de Mzo. de 2022
This is so great

Iniciar sesión para comentar.

Allan Kjærgaard Jensen
Allan Kjærgaard Jensen el 17 de Abr. de 2018

0 votos

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

Categorías

Más información sobre App Building en Centro de ayuda y File Exchange.

Preguntada:

el 10 de Oct. de 2015

Comentada:

el 14 de Mzo. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by