1

I'm trying to write a program that simulates the terminal tab completion. But I'm unsure of how to trap the tab key. This is a non gui application. I'm not looking for swing/awd actionlisteners

Desired Result

While(true)
//Some api to capture KeyEvent.VK_TAB (tab key)
System.out.print("You typed tab")
Tim M.
  • 568
  • 4
  • 15
stackoverflow
  • 17,218
  • 47
  • 124
  • 188

1 Answers1

3

After some googling, i found that there are quite a few java libraries for handling console input. Some of them are:

1. jLine

2. Lanterna

3. Java Curses Library

4. Charva

5. Blacken

jLine have features like custom keybinds, tab completion, line editing etc. jLine have method like readVirtualKey that reads a virtual key from the console e.g. VK_UP.

You can also implement auto complete functionality using tab key. You might have to implement your own Completer class for that. Have a look at the link given below, it clearly shows tab completion functionality. May be that is what you need.

https://jeszysblog.wordpress.com/2012/04/14/readline-style-command-line-editing-with-jline/

lambad
  • 976
  • 9
  • 21