Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Advanced Console Control ( JAVA )

+2 votes
asked Aug 21, 2025 by lhsisphonebad (150 points)
Greetings, I am looking for a Java and OnlineGDB compatible replacement for *nix ncurses. More specifically however - not needing the user to press enter for the program to get keystrokes, much like ncurses cbreak(). More detail would be much appreciated. (ps. termios.h would also be a great help)

Cheers!

2 Answers

+1 vote
answered Aug 21, 2025 by MOHAMMED ASAF CT (160 points)
Java doesn’t natively support raw terminal input like ncurses or termios.h, and since OnlineGDB runs in a restricted environment, capturing keystrokes in real time without pressing Enter isn’t really possible there. If you need advanced console control, you can try libraries like JLine or Lanterna, but they’ll only work if you run the code locally. On OnlineGDB, you’ll have to stick to standard input methods like Scanner or BufferedReader.
+1 vote
answered Aug 22, 2025 by Jerry Jeremiah (2,040 points)

In C or C++ you can use this:

#include <termios.h>
#include <unistd.h>

struct termios setUnbufferedInput() {
    struct termios oldt, newt;
    tcgetattr(STDIN_FILENO, &oldt);
    newt = oldt;
    newt.c_lflag &= ~(ICANON | ECHO);
    tcsetattr(STDIN_FILENO, TCSANOW, &newt);
    return oldt;
}

void resetInput(struct termios oldt) {
    tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
}

In Java you can use a library - but with OnlineGDB there is no way to add a library.
And OnlineGDB only lets you compile C code OR Java code but not both at once - so there is no way to use JNI.
So, I don't think there is any way to do this with OnlineGDB. 

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...