Skip to content

Instantly share code, notes, and snippets.

@mbauman
Created April 17, 2012 19:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbauman/2408587 to your computer and use it in GitHub Desktop.
Save mbauman/2408587 to your computer and use it in GitHub Desktop.
function postKeyEvent
import java.awt.event.KeyEvent
import java.util.Calendar
import java.lang.reflect.*
cmdwin = handle(com.mathworks.mde.desk.MLDesktop.getInstance.getClient('Command Window').getComponent(0).getComponent(0).getComponent(0),'CallbackProperties');
cal = Calendar.getInstance();
tnow = cal.getTime().getTime();
keyEvent = KeyEvent(cmdwin,KeyEvent.KEY_TYPED,tnow,0,KeyEvent.VK_UNDEFINED,'c');
argSig = javaArray('java.lang.Class',1);
argSig(1) = keyEvent.getClass();
args = javaArray('java.lang.Object',1);
args(1) = keyEvent;
method = cmdwin.getClass().getDeclaredMethod('processKeyEvent',argSig);
method.setAccessible(true);
method.invoke(cmdwin,args);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment