本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
}
}
示例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();
}
示例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);
}
}
示例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);
}
示例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();
}
}
};
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}