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

11 views (last 30 days)
Vlad Atanasiu
Vlad Atanasiu on 30 May 2015
Commented: Walter Roberson on 5 Jun 2016
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()
'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

Answers (1)

Walter Roberson
Walter Roberson on 31 May 2015

Sign in to comment.



Community Treasure Hunt

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

Start Hunting!

Translated by