title: Matlab control+enter key on figure
body: <p>I want to capture when the user holds down the control key and presses the enter key on a figure window.  Note: This is the default keys for "Evaluate Current Section" in the editor.</p>
  
  <p>See example code below:</p>
  
  <pre><code>function test
    f = figure;  
    f.KeyPressFcn = @myKeyPressFcn;
  end
  function myKeyPressFcn ( hFig, event )
    cm = hFig.CurrentModifier();  
    if ~isempty ( cm )
      fprintf ( 'CurrentKey: %s:%s\n', cm{1}, hFig.CurrentKey );
    else 
      fprintf ( 'CurrentKey: %s\n', hFig.CurrentKey );
    end
  end
  </code></pre>
  
  <p>To reproduce save the above in an active file in the editor and run the function - the editor needs to be open (this is important!!).</p>
  
  <p>With the figure active press any key -> the selected key is written to the terminal window.  However if you hold down Control and press the enter (return) key then this is not captured but instead Matlab attempts to "Evaluate Current Section" (or cell as it used to be called) in the editor (no matter that the figure has the focus).  This of course throws as error...</p>
  
  <p><em>I have contacted Matlab support and this is "expected behaviour!".  I can (just about) see why it might be a good idea for demos - but for professional applications that run in Matlab I personally think this "feature" is a bug!!</em></p>
  
  <p>Notes</p>
  
  <ol>
  <li>When the editor is closed the control+enter is captured in the figure</li>
  <li>In deployed applications the control+enter is captured.</li>
  <li>If I manually change the Evaluate Current Section shortcut then control+enter is captured.</li>
  </ol>
  
  <p>I have tried a number of things to resolve this but none have worked, for example hiding the editor or setting editor enable state to false (neither of these are acceptable solutions - I was trying to see what I could get to work on a small test case...):</p>
  
  <pre><code>function test
    desktop = com.mathworks.mde.desk.MLDesktop.getInstance;
    jEditor = desktop.getGroupContainer('Editor').getTopLevelAncestor;
    jEditor.setVisible(false);
    jEditor.setEnable(false);
    f = figure
    f.KeyPressFcn = @myKeyPressFcn;
    uiwait(f);
    jEditor.setVisible(true);
    jEditor.setEnable(true);
  end
  </code></pre>
  
  <p>The only way I can get it to work is to close all of the editor files on launching the GUI and then opening them again when the GUI closes (this is not an acceptable solution... - for fairly obvious reasons!!)</p>
  
  <p>I did think about trying to temporarily modify the shortcut key (Preferences-Keyboard-Shortcuts) of the "Evaluate Current Section" -> but haven't worked out a way to do it from the commandline, and then set it back again when finished.  If this is fast you could do it when the user presses and releases the control key.</p>
  
  <p>So what am I asking:</p>
  
  <p>If possible I need a solution that will work for anyone anywhere - as if I can get this to work it will be included in a new add-on feature in <a href="https://sites.google.com/site/matpihome/matlab-gui-framework" rel="noreferrer">my Matlab GUI Toolbox</a>. - which is used by people all over the world.</p>
  
  <ol>
  <li>Do you know how to modify the keyboard shortcuts from the commandline - if so how!</li>
  <li>Any other suggestions?</li>
  <li>My other idea is to change my shortcut to a different key combination - but wheres the fun in that! :)   (I will still have the issue if some user somewhere has altered the execute the current cell to my new combination...)</li>
  </ol>
  
  <p><em>P.S. Thanks for reading this far down!! :)</em></p>