Java Code Examples for com.googlecode.lanterna.input.KeyStroke#isAltDown()

The following examples show how to use com.googlecode.lanterna.input.KeyStroke#isAltDown() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractInteractableComponent.java    From lanterna with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * This method can be overridden to handle various user input (mostly from the keyboard) when this component is in
 * focus. The input method from the interface, {@code handleInput(..)} is final in
 * {@code AbstractInteractableComponent} to ensure the input filter is properly handled. If the filter decides that
 * this event should be processed, it will call this method.
 * @param keyStroke What input was entered by the user
 * @return Result of processing the key-stroke
 */
protected Result handleKeyStroke(KeyStroke keyStroke) {
    // Skip the keystroke if ctrl, alt or shift was down
    if(!keyStroke.isAltDown() && !keyStroke.isCtrlDown() && !keyStroke.isShiftDown()) {
        switch(keyStroke.getKeyType()) {
            case ArrowDown:
                return Result.MOVE_FOCUS_DOWN;
            case ArrowLeft:
                return Result.MOVE_FOCUS_LEFT;
            case ArrowRight:
                return Result.MOVE_FOCUS_RIGHT;
            case ArrowUp:
                return Result.MOVE_FOCUS_UP;
            case Tab:
                return Result.MOVE_FOCUS_NEXT;
            case ReverseTab:
                return Result.MOVE_FOCUS_PREVIOUS;
            case MouseEvent:
                if (isMouseMove(keyStroke)) {
                    // do nothing
                    return Result.UNHANDLED;
                }
                getBasePane().setFocusedInteractable(this);
                return Result.HANDLED;
            default:
        }
    }
    return Result.UNHANDLED;
}
 
Example 2
Source File: VirtualScreen.java    From lanterna with GNU Lesser General Public License v3.0 5 votes vote down vote up
private KeyStroke filter(KeyStroke keyStroke) throws IOException {
    if(keyStroke == null) {
        return null;
    }
    else if(keyStroke.isAltDown() && keyStroke.getKeyType() == KeyType.ArrowLeft) {
        if(viewportTopLeft.getColumn() > 0) {
            viewportTopLeft = viewportTopLeft.withRelativeColumn(-1);
            refresh();
            return null;
        }
    }
    else if(keyStroke.isAltDown() && keyStroke.getKeyType() == KeyType.ArrowRight) {
        if(viewportTopLeft.getColumn() + viewportSize.getColumns() < getTerminalSize().getColumns()) {
            viewportTopLeft = viewportTopLeft.withRelativeColumn(1);
            refresh();
            return null;
        }
    }
    else if(keyStroke.isAltDown() && keyStroke.getKeyType() == KeyType.ArrowUp) {
        if(viewportTopLeft.getRow() > 0) {
            viewportTopLeft = viewportTopLeft.withRelativeRow(-1);
            realScreen.scrollLines(0,viewportSize.getRows()-1,-1);
            refresh();
            return null;
        }
    }
    else if(keyStroke.isAltDown() && keyStroke.getKeyType() == KeyType.ArrowDown) {
        if(viewportTopLeft.getRow() + viewportSize.getRows() < getTerminalSize().getRows()) {
            viewportTopLeft = viewportTopLeft.withRelativeRow(1);
            realScreen.scrollLines(0,viewportSize.getRows()-1,1);
            refresh();
            return null;
        }
    }
    return keyStroke;
}
 
Example 3
Source File: UnixLikeTerminal.java    From lanterna with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void isCtrlC(KeyStroke key) throws IOException {
    if(key != null
            && terminalCtrlCBehaviour == CtrlCBehaviour.CTRL_C_KILLS_APPLICATION
            && key.getCharacter() != null
            && key.getCharacter() == 'c'
            && !key.isAltDown()
            && key.isCtrlDown()) {

        if (isInPrivateMode()) {
            exitPrivateMode();
        }
        System.exit(1);
    }
}
 
Example 4
Source File: MultiWindowManagerTest.java    From lanterna with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public boolean handleInput(KeyStroke key) {
    boolean handled = super.handleInput(key);
    if(!handled) {
        switch(key.getKeyType()) {
            case ArrowDown:
                if(key.isAltDown()) {
                    setPosition(getPosition().withRelativeRow(1));
                }
                else if(key.isCtrlDown()) {
                    setFixedSize(getSize().withRelativeRows(1));
                    labelUnlockWindow.setText("false");
                }
                handled = true;
                break;
            case ArrowLeft:
                if(key.isAltDown()) {
                    setPosition(getPosition().withRelativeColumn(-1));
                }
                else if(key.isCtrlDown() && getSize().getColumns() > 1) {
                    setFixedSize(getSize().withRelativeColumns(-1));
                    labelUnlockWindow.setText("false");
                }
                handled = true;
                break;
            case ArrowRight:
                if(key.isAltDown()) {
                    setPosition(getPosition().withRelativeColumn(1));
                }
                else if(key.isCtrlDown()) {
                    setFixedSize(getSize().withRelativeColumns(1));
                    labelUnlockWindow.setText("false");
                }
                handled = true;
                break;
            case ArrowUp:
                if(key.isAltDown()) {
                    setPosition(getPosition().withRelativeRow(-1));
                }
                else if(key.isCtrlDown() && getSize().getRows() > 1) {
                    setFixedSize(getSize().withRelativeRows(-1));
                    labelUnlockWindow.setText("false");
                }
                handled = true;
                break;
        }
    }
    return handled;
}