I have coded a Swing GUI, which uses KeyAccelerators on JMenuItems. Pressing the keys that trigger the Accelerator for a longer time causes the EventQueue to stack commands and blocking the GUI. I want the AWT Event Queue not to have more than one (or two) KeyEvents with Control Modifier in it. I tried this:
AWTEvent awtevent = Toolkit.getDefaultToolkit()
.getSystemEventQueue().peekEvent();
if (awtevent != null) {
String paramString = awtevent.paramString();
if ((paramString.indexOf("modifiers=Ctrl") != -1 && ((KeyEvent) event)
.isControlDown())) {
((KeyEvent) event).consume();
} else if (paramString.indexOf("modifiers=Ctrl") != -1
&& (paramString.indexOf("keyChar=Undefined") != -1)) {
((KeyEvent) event).consume();
}
}
But its very unreliable as it sometimes consumes an Event that shouldnt be consumed.