title: Detect a keystroke in matlab while viewing a figure?
body: <p>I'm trying to sort through some image data in matlab and want to prompt the user for input about a series of images.  Each time I show an image I want to pause and wait for a keystroke and perform a different action depending on what was pressed.</p>
  
  <p>Current Best Solution:</p>
  
  <pre><code>responses = zeros(length(images),1);
  for i = 1:length(images)
      im = imread(images{i}.fname);
      h = figure(1);
      imshow(im);
  
      % instead of just pause, I want to get the keystroke (k) that was pressed
      waitforbuttonpress;
      k = get(h,'CurrentCharacter');
  
      switch lower(k)
          case 'a'
              responses(i) = 1;
          case 'b'
              responses(i) = 2;
      end
  
  end
  </code></pre>