title: matlab KeyPressFcn for holding a key
body: <p>I would like to allow the user to zoom only while the control key is held (depressed). I have implemented this as follows within a <code>WindowKeyPressFcn</code> callback function:</p>
  
  <pre><code>function keypress_callback(obj, evd, hZoom)
  switch evd.Key
    case 'control'
      set(hZoom,'Enable','on');
  end
  %disp(evd); % used for debugging purposes
  </code></pre>
  
  <p>This function accepts a zoom object handle (<code>hZoom</code>) that is passed from the main program at the moment the callback function is activated (<code>set(hFigure,'WindowKeyPressFcn',{@keypress_callback,hZoom});</code>). I have written a similar <code>WindowKeyReleaseFcn</code> (set via <code>set(hFigure,'WindowKeyReleaseFcn',{@keyrelease_callback,hZoom});</code>) to disable zooming when control is released.</p>
  
  <pre><code>function keyrelease_callback(obj, evd, hZoom)
  switch evd.Key
    case 'control'
      set(hZoom,'Enable','off');
  end
  %disp(evd); % used for debugging purposes
  </code></pre>
  
  <p>The goal is to allow normal zooming behavior (click to zoom in by a factor; shift-click to zoom out by a factor; drag clicking to zoom in on a selected region) only while the <code>Ctrl</code> key is depressed. As soon as this modifier key is released, zooming ability should be disabled.</p>
  
  <p>However, this behavior does not work as intended. Simply testing (by <code>disp(evd)</code>) whether a key is pressed reveals that any number of key presses can be made with arbitrary keys; however, if the pressed key is <code>Ctrl</code>, only one such press can be made, and all subsequent presses of <code>Ctrl</code> are ignored, while all subsequent presses of any other key cause the key to appear in the Matab command window instead of triggering the <code>keypress_callback</code> function. Thus, pressing <code>Ctrl</code> appears to somehow inactivate the <code>keypress_callback</code> function, perhaps because focus is shifted from the figure to the zoom object? As a corollary question, the <code>WindowKeyReleaseFcn</code> seems to work fine for non-modifier keys (the <code>evd</code> shows the correct released key), but the <code>key</code> in <code>evd</code> is empty if the released key is a non-modifier key.</p>
  
  <p>I would be grateful if someone could demonstrate the correct implementation of the control-dependent zoom behavior as envisaged.</p>