/** * Forwards key events directly to the input handler. This is slightly faster than using a * KeyListener because some Swing overhead is avoided. */ public void processKeyEvent(KeyEvent evt) { if (inputHandler == null) return; switch (evt.getID()) { case KeyEvent.KEY_TYPED: inputHandler.keyTyped(evt); break; case KeyEvent.KEY_PRESSED: inputHandler.keyPressed(evt); break; case KeyEvent.KEY_RELEASED: inputHandler.keyReleased(evt); break; } }
private synchronized void type(KeyEvent e) { switch (e.getKeyCode()) { case (KeyEvent.VK_ENTER): if (e.getID() == KeyEvent.KEY_PRESSED) { processCommand(); initCommandPos(); text.setCaretPosition(commandPos); } e.consume(); text.repaint(); break; case (KeyEvent.VK_UP): if (e.getID() == KeyEvent.KEY_PRESSED) prevHistory(); e.consume(); break; case (KeyEvent.VK_DOWN): if (e.getID() == KeyEvent.KEY_PRESSED) nextHistory(); e.consume(); break; case (KeyEvent.VK_LEFT): case (KeyEvent.VK_BACK_SPACE): case (KeyEvent.VK_DELETE): if (text.getCaretPosition() <= commandPos) e.consume(); break; case (KeyEvent.VK_HOME): text.setCaretPosition(commandPos); e.consume(); break; case (KeyEvent.VK_U): if ((e.getModifiers() & InputEvent.CTRL_MASK) > 0) { replaceConsoleText("", commandPos, textLength()); commandHistoryIndex = 0; e.consume(); } break; case (KeyEvent.VK_ALT): case (KeyEvent.VK_CAPS_LOCK): case (KeyEvent.VK_CONTROL): case (KeyEvent.VK_META): case (KeyEvent.VK_SHIFT): case (KeyEvent.VK_PRINTSCREEN): case (KeyEvent.VK_SCROLL_LOCK): case (KeyEvent.VK_PAUSE): case (KeyEvent.VK_INSERT): case (KeyEvent.VK_F1): case (KeyEvent.VK_F2): case (KeyEvent.VK_F3): case (KeyEvent.VK_F4): case (KeyEvent.VK_F5): case (KeyEvent.VK_F6): case (KeyEvent.VK_F7): case (KeyEvent.VK_F8): case (KeyEvent.VK_F9): case (KeyEvent.VK_F10): case (KeyEvent.VK_F11): case (KeyEvent.VK_F12): case (KeyEvent.VK_ESCAPE): case (KeyEvent.VK_C): break; default: if ((e.getModifiers() & (InputEvent.CTRL_MASK | InputEvent.ALT_MASK | InputEvent.META_MASK)) == 0) { moveCaret(); } if ((e.paramString().contains("Backspace")) && (text.getCaretPosition() <= commandPos)) { e.consume(); } break; } }