In lanterna, how can I read keyboard inputs like Enter or F1? I need to be able to listen to the keyboard input at all times to take actions, as well as listen to the enter key to read the content of the textbox.
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);
}
I tried an infinite cycle but it is unreachable after the window is waiting. gui.addWindowAndWait (window);
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());
}
}
Thank you!