title: Matlab: allowing cursor and keyboard input simultaneously
body: <p>I want to display a plot, and then wait for <em>either</em> the cursor to be clicked on the plot, <em>or</em> the user to enter a number into Matlab by pressing a key. So far, I know how to both of these individually, but I don't know how to allow Matlab to response to both independently. I suppose you would call this a form of multi-threading.</p>
  
  <p>My code to enable a response when the cursor is clicked is as follows:</p>
  
  <pre><code>h = figure( %{ ... params ...%} );
  while true
      figure(h);
      cursor = ginput(1);
      % ... process the cursor input ...
  end
  </code></pre>
  
  <p>Now, I want to include the following line to enable the user to input a number from the keyboard:</p>
  
  <pre><code>num = input('Enter the number: ' );
  </code></pre>
  
  <p>But if I just add this to my while loop:</p>
  
  <pre><code>h = figure( %{ ... params ...%} );
  while true
      figure(h);
      cursor = ginput(1);
      % ... process the cursor input ...
      num = input('Enter the number: ' ); 
      % ... process the keyboard input ...
  end
  </code></pre>
  
  <p>Then the program will always wait for the user to enter a number from the keyboard before returning to look for a cursor input. But I want the program to respond to both independently of each other.</p>
  
  <p>What's the solution?</p>