How to keep the zoom active as long as a key is pressed?

I want the zoom to be activated by pressing a key and stay active as long as the key is pressed. With the following code, unfortunately, the zoom is activated at key press, then focus is transferred from the figure to the command window, and the pressed key is output at the command line as long as hold down. Any suggestion for a solution?
The utility of keeping the zoom active by key press is to have a faster entry/exit in zoom mode than clicking on the two toolbar icons.
function zoomOnKeyPress()
figure(...
'KeyPressFcn', @KeyPressFcn, ...
'KeyReleaseFcn', @KeyReleaseFcn);
function KeyPressFcn(h,e)
zoom on
hf = gcf;
hf.Color = 'red'; % show that we are here
function KeyReleaseFcn(h,e)
zoom off
hf = gcf;
hf.Color = 'green'; % show that we are here

Réponses (1)

Walter Roberson
Walter Roberson le 31 Mai 2015

0 votes

4 commentaires

Thanks Walter! It appears however that in R2014b I can't modify WindowListenerHandles . I see that its SetAccess property is set to protected . Additionally, the former property Enable , a string ( 'on' | 'off' ), is now called Enabled and is a scalar ( 0|1 ).
hManager = uigetmodemanager(gcf);
mc = metaclass(hManager)
mc.PropertyList(5)
Sorry, I only have up to R2014a here. I always considered turning off the protection to be a kludge so I am not surprised that it now fails. I would suggest going over to UndocumentedMatlab and looking around there and asking there.
Igor
Igor le 4 Juin 2016
Modifié(e) : Igor le 4 Juin 2016
If anyone is still looking for an answer - the difference between R2014b and older versions is not very large - the fix is described here. For a more complete example, take a look at this submission.
Thanks, Igor.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Startup and Shutdown dans Centre d'aide et File Exchange

Produits

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by