如何获得输入或F1等键盘输入?我需要在按下回车键后获取文本框内容。我无论如何都需要获得F1和其他钥匙。
public static void main(String[] args) throws IOException, InterruptedException {
SpringApplication.run(LanternaApplication.class, args);
TelnetTerminalServer server = new TelnetTerminalServer(2000, Charset.forName("utf8"));
final TelnetTerminal telnetTerminal = server.acceptConnection();
KeyStroke keyPressed = telnetTerminal.readInput();
System.out.println("keyPressed: " + keyPressed.getKeyType());
// Setup screen layers
Screen screen = new TerminalScreen(telnetTerminal);
screen.startScreen();
// Create main panel to hold components
Panel mainPanel = new Panel();
mainPanel.setLayoutManager(new GridLayout(1));
//input
final TextBox tbox = new TextBox(new TerminalSize(40, 1));
tbox.withBorder(Borders.singleLine());
mainPanel.addComponent(tbox);
//label
mainPanel.addComponent(new Label("New Label"));
// Create window to hold the panel
BasicWindow window = new BasicWindow();
window.setComponent(mainPanel);
// Create gui and start gui
MultiWindowTextGUI gui = new MultiWindowTextGUI(screen, new DefaultWindowManager(), new EmptySpace(TextColor.ANSI.DEFAULT));
gui.addWindowAndWait(window) }
我尝试过使用无限循环,但是在gui.addWindowAndWait(窗口)之后我无法达到它;
while(true){
// Read input
KeyStroke keyPressed = telnetTerminal.readInput();
// Check the input for the "tab" key
if (keyPressed.getKeyType() == KeyType.F1){
System.out.println("keyPressed: " + keyPressed.getKeyType());
}
}
谢谢!
答案 0 :(得分:1)
您可能希望实现CREATE INDEX ep ON EventPVE(idPlayer);
CREATE INDEX pkiller ON EventPVP(idPlayerKiller);
CREATE INDEX pkilled ON EventPVP(idPlayerKilled);
,如下所示:
WindowListener
然后将监听器添加到窗口:
public class KeyStrokeListener implements WindowListener {
public void onInput(Window basePane, KeyStroke keyStroke, AtomicBoolean deliverEvent) {
System.out.println("Pressed: "+ keyStroke);
}
public void onUnhandledInput(Window basePane, KeyStroke keyStroke, AtomicBoolean hasBeenHandled) {
// TODO Auto-generated method stub
}
public void onResized(Window window, TerminalSize oldSize, TerminalSize newSize) {
// TODO Auto-generated method stub
}
public void onMoved(Window window, TerminalPosition oldPosition, TerminalPosition newPosition) {
// TODO Auto-generated method stub
}
}
你应该得到的输出:
public static void main(String[] args) throws IOException {
TelnetTerminalServer server = new TelnetTerminalServer(2000, Charset.forName("utf8"));
final TelnetTerminal telnetTerminal = server.acceptConnection();
KeyStroke keyPressed = telnetTerminal.readInput();
System.out.println("keyPressed: " + keyPressed.getKeyType());
// Setup screen layers
Screen screen = new TerminalScreen(telnetTerminal);
screen.startScreen();
// Create main panel to hold components
Panel mainPanel = new Panel();
mainPanel.setLayoutManager(new GridLayout(1));
// Input
final TextBox tbox = new TextBox(new TerminalSize(40, 1));
tbox.withBorder(Borders.singleLine());
mainPanel.addComponent(tbox);
// Label
mainPanel.addComponent(new Label("New Label"));
// Create window to hold the panel
BasicWindow window = new BasicWindow();
window.setComponent(mainPanel);
KeyStrokeListener listener = new KeyStrokeListener();
window.addWindowListener(listener);
// Create GUI and start it
MultiWindowTextGUI gui = new MultiWindowTextGUI(screen, new DefaultWindowManager(), new EmptySpace(TextColor.ANSI.DEFAULT));
gui.addWindowAndWait(window);
}