Hello,
You can initialize KeyEventDispatcher as a class variable. And then in onStop() method remove your eventDispatcher from KeyboardFocusManager. Then Key Events control will be returned to default dispatcher.
private KeyEventDispatcher eventDispatcher;
@Override
public void onStart(IContext context) throws JFException {
this.engine = context.getEngine();
this.console = context.getConsole();
this.history = context.getHistory();
this.context = context;
this.indicators = context.getIndicators();
this.userInterface = context.getUserInterface();
eventDispatcher = event -> {
boolean discardEvent = false;
int closeMAsk = KeyEvent.CTRL_DOWN_MASK + 82;
if (((event.getModifiersEx() + event.getKeyCode()) == closeMAsk)
&& event.paramString().indexOf("KEY_PRESSED") >= 0) {
console.getOut().println("ctrl-r pressed");
context.executeTask(new OnKeyTask());
discardEvent = true;
}
return discardEvent;
};
KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(eventDispatcher);
}
@Override
public void onStop() throws JFException {
KeyboardFocusManager.getCurrentKeyboardFocusManager().removeKeyEventDispatcher(eventDispatcher);
}