• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java KeyStroke类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: readKeyStroke

import com.googlecode.lanterna.input.KeyStroke; //导入依赖的package包/类
@Override
protected synchronized KeyStroke readKeyStroke() throws IOException {
    KeyStroke keyStroke = super.pollInput();
    if(eofWhenNoWindows && keyStroke == null && windows.isEmpty()) {
        return new KeyStroke(KeyType.EOF);
    }
    else if(keyStroke != null) {
        return keyStroke;
    }
    else {
        return super.readKeyStroke();
    }
}
 
开发者ID:Truth0906,项目名称:lanterna,代码行数:14,代码来源:MultiWindowTextGUI.java


示例17: handleInput

import com.googlecode.lanterna.input.KeyStroke; //导入依赖的package包/类
@Override
public synchronized boolean handleInput(KeyStroke keyStroke) {
    Window activeWindow = getActiveWindow();
    if(activeWindow != null) {
        return activeWindow.handleInput(keyStroke);
    }
    else {
        return backgroundPane.handleInput(keyStroke);
    }
}
 
开发者ID:Truth0906,项目名称:lanterna,代码行数:11,代码来源:MultiWindowTextGUI.java


示例18: fireUnhandledKeyStroke

import com.googlecode.lanterna.input.KeyStroke; //导入依赖的package包/类
protected boolean fireUnhandledKeyStroke(KeyStroke keyStroke) {
    boolean handled = false;
    for(Listener listener: listeners) {
        handled = listener.onUnhandledKeyStroke(this, keyStroke) || handled;
    }
    return handled;
}
 
开发者ID:Truth0906,项目名称:lanterna,代码行数:8,代码来源:AbstractTextGUI.java


示例19: filter

import com.googlecode.lanterna.input.KeyStroke; //导入依赖的package包/类
private KeyStroke filter(KeyStroke keyStroke) throws IOException {
    if(keyStroke == null) {
        return null;
    }
    else if(keyStroke.isCtrlDown() && keyStroke.getKeyType() == KeyType.ArrowLeft) {
        if(viewportTopLeft.getColumn() > 0) {
            viewportTopLeft = viewportTopLeft.withRelativeColumn(-1);
            refresh();
        }
        return null;
    }
    else if(keyStroke.isCtrlDown() && keyStroke.getKeyType() == KeyType.ArrowRight) {
        if(viewportTopLeft.getColumn() + viewportSize.getColumns() < getTerminalSize().getColumns()) {
            viewportTopLeft = viewportTopLeft.withRelativeColumn(1);
            refresh();
        }
        return null;
    }
    else if(keyStroke.isCtrlDown() && 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.isCtrlDown() && 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;
}
 
开发者ID:Truth0906,项目名称:lanterna,代码行数:37,代码来源:VirtualScreen.java


示例20: pollInput

import com.googlecode.lanterna.input.KeyStroke; //导入依赖的package包/类
@Override
public KeyStroke pollInput() {
    try {
        return backend.pollInput();
    }
    catch(IOException e) {
        exceptionHandler.onException(e);
    }
    return null;
}
 
开发者ID:Truth0906,项目名称:lanterna,代码行数:11,代码来源:IOSafeTerminalAdapter.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SnmpEngineImpl类代码示例发布时间:2022-05-22
下一篇:
Java InvalidArgument类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap