MATLAB: How to implement zooming using key presses while user is selecting points using GINPUT in MATLAB 7.4 (R2007a)

MATLAB

I have an application where the user needs to select several points from the figure. I am implementing this using the function GINPUT.
However, while selecting points using the mouse during the execution of GINPUT, I want to be able to zoom/pan the figure using key presses.
The KEYPRESSFCN callback does not fire while GINPUT is being executed. I am wondering how to implement this functionality.

Best Answer

It is possible to modify the function GINPUT so that while selecting points using mouse one can also use key presses to have more functionality like zoom/pan the figure.
GINPUT uses the function WAITFORBUTTONPRESS to wait until the user clicks the mouse or hits a key. As soon as these events occur the pointer locations are stored. This code can be modified by implementing a while loop which keeps on scanning for points until the user clicks the mouse, hits Ctrl+C, or hits Enter. The code can contain IF conditions to take appropriate keypress actions when the user hits other keys.
Please refer to the attached 'my_ginput' function which can zoom in/out when the user presses r/v while selecting points on the figure.
You can extend the WFBP subfunction in the file in a similar manner to implement panning functionality.