public void handleKeyEvent(KeyEvent e) { final int id = e.getID(); if (id == KeyEvent.KEY_PRESSED) { myKeyListener.keyPressed(e); } else if (id == KeyEvent.KEY_RELEASED) { /* keyReleased(e); */ } else if (id == KeyEvent.KEY_TYPED) { myKeyListener.keyTyped(e); } }
private void processTerminalKeyTyped(KeyEvent e) { final char keychar = e.getKeyChar(); if ((keychar & 0xff00) != 0) { final char[] foo; if (mySettingsProvider.altSendsEscape() && (e.getModifiers() & InputEvent.ALT_MASK) != 0) { foo = new char[] {Ascii.ESC, keychar}; } else { foo = new char[] {keychar}; } try { myTerminalStarter.sendString(new String(foo)); if (mySettingsProvider.scrollToBottomOnTyping()) { scrollToBottom(); } } catch (final RuntimeException ex) { LOG.error("Error sending key to emulator", ex); } } }
private void processTerminalKeyPressed(KeyEvent e) { try { final int keycode = e.getKeyCode(); final char keychar = e.getKeyChar(); // numLock does not change the code sent by keypad VK_DELETE // although it send the char '.' if (keycode == KeyEvent.VK_DELETE && keychar == '.') { myTerminalStarter.sendBytes(new byte[] {'.'}); return; } // CTRL + Space is not handled in KeyEvent; handle it manually else if (keychar == ' ' && (e.getModifiers() & InputEvent.CTRL_MASK) != 0) { myTerminalStarter.sendBytes(new byte[] {Ascii.NUL}); return; } final byte[] code = myTerminalStarter.getCode(keycode, e.getModifiers()); if (code != null) { myTerminalStarter.sendBytes(code); if (mySettingsProvider.scrollToBottomOnTyping() && isCodeThatScrolls(keycode)) { scrollToBottom(); } } else if ((keychar & 0xff00) == 0) { final byte[] obuffer; if (mySettingsProvider.altSendsEscape() && (e.getModifiers() & InputEvent.ALT_MASK) != 0) { obuffer = new byte[] {Ascii.ESC, (byte) keychar}; } else { obuffer = new byte[] {(byte) keychar}; } myTerminalStarter.sendBytes(obuffer); if (mySettingsProvider.scrollToBottomOnTyping()) { scrollToBottom(); } } } catch (final Exception ex) { LOG.error("Error sending key to emulator", ex); } }
@Override public void processKeyEvent(final KeyEvent e) { handleKeyEvent(e); e.consume(); }