当前位置: 首页>>代码示例>>Java>>正文


Java KeyStroke类代码示例

本文整理汇总了Java中com.googlecode.lanterna.input.KeyStroke的典型用法代码示例。如果您正苦于以下问题:Java KeyStroke类的具体用法?Java KeyStroke怎么用?Java KeyStroke使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


KeyStroke类属于com.googlecode.lanterna.input包,在下文中一共展示了KeyStroke类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: processInput

import com.googlecode.lanterna.input.KeyStroke; //导入依赖的package包/类
@Override
public synchronized boolean processInput() throws IOException {
    boolean gotInput = false;
    KeyStroke keyStroke = readKeyStroke();
    if(keyStroke != null) {
        gotInput = true;
        do {
            if (keyStroke.getKeyType() == KeyType.EOF) {
                throw new EOFException();
            }
            boolean handled = handleInput(keyStroke);
            if(!handled) {
                handled = fireUnhandledKeyStroke(keyStroke);
            }
            dirty = handled || dirty;
            keyStroke = pollInput();
        } while(keyStroke != null);
    }
    return gotInput;
}
 
开发者ID:Truth0906,项目名称:lanterna,代码行数:21,代码来源:AbstractTextGUI.java

示例2: handleKeyStroke

import com.googlecode.lanterna.input.KeyStroke; //导入依赖的package包/类
@Override
public Result handleKeyStroke(KeyStroke keyStroke) {
    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:
            getBasePane().setFocusedInteractable(this);
            return Result.HANDLED;
        default:
    }
    return Result.UNHANDLED;
}
 
开发者ID:Truth0906,项目名称:lanterna,代码行数:23,代码来源:AbstractInteractableComponent.java

示例3: stopScreen

import com.googlecode.lanterna.input.KeyStroke; //导入依赖的package包/类
@Override
public synchronized void stopScreen() throws IOException {
    if(!isStarted) {
        return;
    }

    //Drain the input queue
    KeyStroke keyStroke;
    do {
        keyStroke = pollInput();
    }
    while(keyStroke != null && keyStroke.getKeyType() != KeyType.EOF);

    getTerminal().exitPrivateMode();
    isStarted = false;
}
 
开发者ID:Truth0906,项目名称:lanterna,代码行数:17,代码来源:TerminalScreen.java

示例4: readInput

import com.googlecode.lanterna.input.KeyStroke; //导入依赖的package包/类
private KeyStroke readInput(boolean blocking) throws IOException {
    synchronized(readMutex) {
        if(!keyQueue.isEmpty())
            return keyQueue.poll();

        KeyStroke key = inputDecoder.getNextCharacter(blocking);
        if (key != null && key.getKeyType() == KeyType.CursorLocation) {
            TerminalPosition reportedTerminalPosition = inputDecoder.getLastReportedTerminalPosition();
            if (reportedTerminalPosition != null)
                onResized(reportedTerminalPosition.getColumn(), reportedTerminalPosition.getRow());

            return pollInput();
        } else {
            return key;
        }
    }
}
 
开发者ID:Truth0906,项目名称:lanterna,代码行数:18,代码来源:StreamBasedTerminal.java

示例5: main

import com.googlecode.lanterna.input.KeyStroke; //导入依赖的package包/类
public static void main(String[] args) throws InterruptedException, IOException {
    Terminal terminal = new TestTerminalFactory(args).createTerminal();
    terminal.enterPrivateMode();
    terminal.clearScreen();
    terminal.setCursorPosition(10, 5);
    terminal.putCharacter('H');
    terminal.putCharacter('e');
    terminal.putCharacter('l');
    terminal.putCharacter('l');
    terminal.putCharacter('o');
    terminal.putCharacter('!');
    terminal.setCursorPosition(0, 0);
    terminal.addResizeListener(new TerminalResizeTest());

    while(true) {
        KeyStroke key = terminal.pollInput();
        if(key == null || key.getCharacter() != 'q') {
            Thread.sleep(1);
        }
        else {
            break;
        }
    }
    terminal.exitPrivateMode();
}
 
开发者ID:Truth0906,项目名称:lanterna,代码行数:26,代码来源:TerminalResizeTest.java

示例6: readInputMapping

import com.googlecode.lanterna.input.KeyStroke; //导入依赖的package包/类
private Map<KeyStroke, Input> readInputMapping() {
    if (!INPUT_MAPPING_FILE.exists()) {
        return null;
    }
    final Properties inputMapping = new Properties();
    try (final BufferedReader reader = Files.newReader(INPUT_MAPPING_FILE, StandardCharsets.UTF_8)) {
        inputMapping.load(reader);
        final Map<KeyStroke, Input> result = Maps.newHashMap();
        for (final Input input : Input.values()) {
            final String keyStrokes = inputMapping.getProperty(input.name());
            if (Strings.isNullOrEmpty(keyStrokes)) {
                throw new IllegalStateException(String.format("No key binding for input [%s].", input));
            }
            for (final String keyStroke : Splitter.on(",").split(keyStrokes)) {
                result.put(KeyStrokes.fromString(keyStroke), input);
            }
        }
        return result;
    } catch (final Exception exception) {
        throw new RuntimeException("Unable to read input mapping file.", exception);
    }
}
 
开发者ID:klaushauschild1984,项目名称:ff7rl,代码行数:23,代码来源:InputMapping.java

示例7: handleKeyStroke

import com.googlecode.lanterna.input.KeyStroke; //导入依赖的package包/类
@Override
public Result handleKeyStroke(KeyStroke keyStroke) {
	Runnable selectedItem = getSelectedItem();
	KeyType keyType = keyStroke.getKeyType();
	if (selectedItem != null
			&& (keyType == KeyType.Enter || (keyType == KeyType.Character && keyStroke.getCharacter() == ' '))) {
		selectedItem.run();
		return Result.HANDLED;
	}
	if (keyType == KeyType.Character) {
		selectItem(keyStroke.getCharacter());
	}
	if (keyType == KeyType.Escape) {
		closeListener.run();
		return Result.HANDLED;
	}
	return super.handleKeyStroke(keyStroke);
}
 
开发者ID:BrunoEberhard,项目名称:minimal-j,代码行数:19,代码来源:MenuItemListBox.java

示例8: createKeyInputAwarePrinter

import com.googlecode.lanterna.input.KeyStroke; //导入依赖的package包/类
public static SessionStatePrinter createKeyInputAwarePrinter(Collection<KeyStrokeBinding> bindings) {
    return new SessionStatePrinter() {
        private Thread t;

        {
            t = new Thread(() -> {
                while (!isShutdown()) {
                    try {
                        KeyStroke keyStroke = readKeyInput();
                        if (keyStroke.isCtrlDown() && keyStroke.getKeyType() == KeyType.Character
                                && keyStroke.getCharacter().equals('c')) {
                            shutdown();
                            System.exit(0);
                        } else {
                            bindings.forEach(binding -> {
                                if (keyStroke.equals(binding.getKeyStroke())) {
                                    binding.getBinding().run();
                                }
                            });
                        }
                    } catch (Throwable e) {
                        LOGGER.error("Unexpected error when reading user input", e);
                    }
                }
            });
            t.setDaemon(true);
            t.start();

            Runtime.getRuntime().addShutdownHook(new Thread(this::shutdown));
        }

        @Override
        public void shutdown() {
            if (!isShutdown()) {
                super.shutdown();
                t.interrupt();
            }
        }
    };
}
 
开发者ID:atomashpolskiy,项目名称:bt,代码行数:41,代码来源:SessionStatePrinter.java

示例9: handleKeyStroke

import com.googlecode.lanterna.input.KeyStroke; //导入依赖的package包/类
@Override
public Result handleKeyStroke(KeyStroke keyStroke) {
    Object selectedItem = getSelectedItem();
    if(selectedItem != null &&
            (keyStroke.getKeyType() == KeyType.Enter ||
            (keyStroke.getKeyType() == KeyType.Character && keyStroke.getCharacter() == ' '))) {

        ((Runnable)selectedItem).run();
        return Result.HANDLED;
    }
    return super.handleKeyStroke(keyStroke);
}
 
开发者ID:Truth0906,项目名称:lanterna,代码行数:13,代码来源:ActionListBox.java

示例10: handleKeyStroke

import com.googlecode.lanterna.input.KeyStroke; //导入依赖的package包/类
@Override
public Result handleKeyStroke(KeyStroke keyStroke) {
    if(keyStroke.getKeyType() == KeyType.Enter) {
        action.run();
        return Result.HANDLED;
    }
    return super.handleKeyStroke(keyStroke);
}
 
开发者ID:Truth0906,项目名称:lanterna,代码行数:9,代码来源:Button.java

示例11: handleKeyStroke

import com.googlecode.lanterna.input.KeyStroke; //导入依赖的package包/类
@Override
public Result handleKeyStroke(AbstractListBox<V, T> listBox, KeyStroke keyStroke) {
    switch (keyStroke.getKeyType()) {
        case PageUp:
            listBox.setSelectedIndex(listBox.getSelectedIndex() - pageSize);
            return Result.HANDLED;

        case PageDown:
            listBox.setSelectedIndex(listBox.getSelectedIndex() + pageSize);
            return Result.HANDLED;

        default:
    }
    return Result.UNHANDLED;
}
 
开发者ID:Truth0906,项目名称:lanterna,代码行数:16,代码来源:AbstractListBox.java

示例12: handleKeyStroke

import com.googlecode.lanterna.input.KeyStroke; //导入依赖的package包/类
@Override
public synchronized Result handleKeyStroke(KeyStroke keyStroke) {
    if(keyStroke.getKeyType() == KeyType.Enter ||
            (keyStroke.getKeyType() == KeyType.Character && keyStroke.getCharacter() == ' ')) {
        if(itemStatus.get(getSelectedIndex()))
            itemStatus.set(getSelectedIndex(), Boolean.FALSE);
        else
            itemStatus.set(getSelectedIndex(), Boolean.TRUE);
        return Result.HANDLED;
    }
    return super.handleKeyStroke(keyStroke);
}
 
开发者ID:Truth0906,项目名称:lanterna,代码行数:13,代码来源:CheckBoxList.java

示例13: handleKeyStroke

import com.googlecode.lanterna.input.KeyStroke; //导入依赖的package包/类
@Override
public Result handleKeyStroke(KeyStroke keyStroke) {
    if((keyStroke.getKeyType() == KeyType.Character && keyStroke.getCharacter() == ' ') ||
            keyStroke.getKeyType() == KeyType.Enter) {
        setChecked(!isChecked());
        return Result.HANDLED;
    }
    return super.handleKeyStroke(keyStroke);
}
 
开发者ID:Truth0906,项目名称:lanterna,代码行数:10,代码来源:CheckBox.java

示例14: handleInput

import com.googlecode.lanterna.input.KeyStroke; //导入依赖的package包/类
@Override
public boolean handleInput(KeyStroke key) {
    if(key.getKeyType() == KeyType.Escape) {
        close();
        return true;
    }
    return super.handleInput(key);
}
 
开发者ID:Truth0906,项目名称:lanterna,代码行数:9,代码来源:AbstractWindow.java

示例15: handleKeyStroke

import com.googlecode.lanterna.input.KeyStroke; //导入依赖的package包/类
@Override
public synchronized Result handleKeyStroke(KeyStroke keyStroke) {
    if(keyStroke.getKeyType() == KeyType.Enter ||
            (keyStroke.getKeyType() == KeyType.Character && keyStroke.getCharacter() == ' ')) {
        checkedIndex = getSelectedIndex();
        invalidate();
        return Result.HANDLED;
    }
    return super.handleKeyStroke(keyStroke);
}
 
开发者ID:Truth0906,项目名称:lanterna,代码行数:11,代码来源:RadioBoxList.java


注:本文中的com.googlecode.lanterna.input.KeyStroke类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。