FigureがズームモードのときにWindowKeyPressFcnを使用したいと思っています。この質問は最近ここにOverriding ctrl-z behavior in matlab zoom modeと尋ねられましたが、私はちょうど同じ問題を示すための最小限の例を作ったばかりです(自分の投稿にコメントを書いたが、まだ十分な担当者がいません)。誰か私たちが逃していることを知っていますかMATLABズームモードでキーを押すのを聞く
function listenWhileZooming
%% Main problem:
% I want any key press to change the color of the plot, even when in Zoom
% mode. I tried to override the mode manager, but don't see any effect.
%%
%% Create and then hide the GUI as it is being constructed
f = figure('Visible','off','units','normalized','Position',[0.1 0.1 0.5 0.5],'windowkeypressfcn',@colorSwap);
%% Override mode manager
hManager = uigetmodemanager(f);
try
set(hManager.WindowListenerHandles, 'Enable', 'off'); % HG1
catch
[hManager.WindowListenerHandles.Enabled] = deal(false); % HG2
end
set(f, 'WindowKeyPressFcn',@colorSwap);
%% Plot something
plot(1,1,'bo')
%% Make the GUI visible
f.Visible = 'on';
%% Key press callback
function colorSwap(source,eventData)
myLine = findobj(source,'type','line');
if all(myLine.Color == [0 0 1])
plot(1,1,'ro')
else
plot(1,1,'bo')
end
end
end