use of com.googlecode.lanterna.input.KeyType in project narchy by automenta.
the class ConsoleTerminal method onKey.
@Override
public boolean onKey(KeyEvent e, boolean pressed) {
int cc = e.getKeyCode();
if (pressed && cc == 13) {
term.addInput(new KeyStroke(KeyType.Enter, e.isControlDown(), e.isAltDown(), e.isShiftDown()));
} else if (pressed && cc == 8) {
term.addInput(new KeyStroke(KeyType.Backspace, e.isControlDown(), e.isAltDown(), e.isShiftDown()));
} else if (pressed && cc == 27) {
term.addInput(new KeyStroke(KeyType.Escape, e.isControlDown(), e.isAltDown(), e.isShiftDown()));
} else if (e.isPrintableKey() && !e.isActionKey() && !e.isModifierKey()) {
char c = e.getKeyChar();
if (!TerminalTextUtils.isControlCharacter(c) && pressed) /* release */
{
// eterm.gui.getActiveWindow().handleInput(
term.addInput(// eterm.gui.handleInput(
new KeyStroke(c, e.isControlDown(), e.isAltDown(), e.isShiftDown()));
} else {
return false;
}
} else if (pressed) {
KeyType c = null;
// System.out.println(" keycode: " + e.getKeyCode());
switch(e.getKeyCode()) {
case KeyEvent.VK_BACK_SPACE:
c = KeyType.Backspace;
break;
case KeyEvent.VK_ENTER:
c = KeyType.Enter;
break;
case KeyEvent.VK_INSERT:
c = KeyType.Insert;
break;
case KeyEvent.VK_HOME:
c = KeyType.Home;
break;
case KeyEvent.VK_END:
c = KeyType.End;
break;
case KeyEvent.VK_DELETE:
c = KeyType.Delete;
break;
case KeyEvent.VK_LEFT:
c = KeyType.ArrowLeft;
break;
case KeyEvent.VK_RIGHT:
c = KeyType.ArrowRight;
break;
case KeyEvent.VK_UP:
c = KeyType.ArrowUp;
break;
case KeyEvent.VK_DOWN:
c = KeyType.ArrowDown;
break;
default:
// System.err.println("character not handled: " + e);
return false;
}
// eterm.gui.handleInput(
// eterm.gui.getActiveWindow().handleInput(
term.addInput(new KeyStroke(c, e.isControlDown(), e.isAltDown(), e.isShiftDown()));
// KeyEvent.isModifierKey(KeyEvent.VK_CONTROL),
// KeyEvent.isModifierKey(KeyEvent.VK_ALT),
// KeyEvent.isModifierKey(KeyEvent.VK_SHIFT)
// ));
} else {
// ...
}
return true;
}