- Create the figure and the plot as you did and store the figure handle.
- After the zoom button is pressed, disable the window listener as you had earlier. The only change you need to make is to instead pass your function to the "WindowKeyPressFcn" callback instead of the "KeyPressFcn". So the code should look as follows:
Re-enable keypress capture when de-selecting figure
26 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have KeyPressFcn for my figure. When you click some other object/command to lose focus of the figure, it is no longer listening for key presses. I've read about this issue in a few places, including here: http://undocumentedmatlab.com/blog/enabling-user-callbacks-during-zoom-pan
I want to be able to do the following after plotting a figure: 1) Click the zoom button and zoom in on an axes 2) Use a keyboard key KeyPressFcn while the zoom button in the toolbar is still depressed.
Unfortunately, I can't get the fix to work. The only way to get my figure KeyPressFcn working again is to de-select the zoom icon. Here's my code:
main.m:
figure_handle = figure(1);
plot(rand(1,10),rand(1,10));
% Fix from http://undocumentedmatlab.com/blog/enabling-user-callbacks-during-zoom-pan
hManager = uigetmodemanager(figure_handle);
[hManager.WindowListenerHandles.Enabled] = deal(false); % HG2
set(figure_handle, 'WindowKeyPressFcn', []);
set(figure_handle, 'KeyPressFcn', @(hobj,evnt) myKeyPress(hobj,evnt));
myKeyPress.m:
function myKeyPress(hfig, eventDat)
disp('success')
end
Any idea what I'm doing wrong? I want the figure key presses to still work if the user tries to zoom/pan an axes, without having to de-select that operation when they're done.
0 comentarios
Respuestas (1)
Jordan Ross
el 23 de En. de 2017
Hello,
So I was able to get it working by doing the following:
hManager = uigetmodemanager(figure_handle);
[hManager.WindowListenerHandles.Enabled] = deal(false); % HG2
set(figure_handle, 'WindowKeyPressFcn', @(hobj,evnt) myKeyPress(hobj,evnt));
I have tried this out on R2016b and was able to achieve the intended result.
0 comentarios
Ver también
Categorías
Más información sobre Specifying Target for Graphics Output 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!