void (int javaKeyEventCode) { EventQueue systemEventQueue = Toolkit.getDefaultToolkit().getSystemEventQueue(); systemEventQueue.postEvent( new KeyEvent(new JPanel(), KeyEvent.KEY_PRESSED, System.currentTimeMillis(), 0, javaKeyEventCode, KeyEvent.CHAR_UNDEFINED) ); systemEventQueue.postEvent( new KeyEvent(new JPanel(), KeyEvent.KEY_RELEASED, System.currentTimeMillis(), 0, javaKeyEventCode, KeyEvent.CHAR_UNDEFINED) ); }