keypress callback in figure works but always send a copy of key to matlab command line afterwards

2 visualizaciones (últimos 30 días)
Hi,I am writing a callback to a figure:
f=figure;
imagesc(rand(56,67))
% set(f,'KeyPressFcn',[]);
set(f,'WindowKeyPressFcn',@(Obj,EventData)loomFigureCallback(Obj,EventData,f))
function loomFigureCallback(Obj,EventData,f)
figure(f);
if uint8(EventData.Character)==27
a = zoom;a.enable = 'off';
pan off
elseif strcmpi(EventData.Character,'M') % Esc button
a = zoom;a.enable = 'on';
elseif strcmpi(EventData.Character,'P')
pan on
elseif strcmpi(EventData.Character,'X')
zoom xon
elseif strcmpi(EventData.Character,'Y')
zoom yon
elseif strcmpi(EventData.Character,'Z')
zoom on
end
end
When the figure toogle bar button is not selected, the key callback works well (e.g., press P will make the pan button selected, and then callback is ignored untill exited by hand-click on pan button to exit).
The problem is that when I press any button, the key was also typed immediately into the command line and make the matlab main panel active, no matter the key has callback or not.
Is there a way to let matlab not acquire focus when pressing a key?
Thanks.

Respuestas (0)

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by