#include <stdio.h> #include <ncurses.h> int main(int argc, char *argv) { char input; initscr(); // entering ncurses mode raw(); // CTRL-C and others do not generate signals noecho(); // pressed symbols wont be printed to screen cbreak(); // disable line buffering while (1) { erase(); mvprintw(1,0, "Enter symbol, please"); input = getch(); mvprintw(2,0, "You have entered %c", input); getch(); // press any key to continue } endwin(); // leaving ncurses mode return 0; }
When creating your program, remember to link the ncurses lib (-L lncurses) flag with gcc
gcc -g -o sample sample.c -L lncurses
And here you can see the kbhit () implementation for linux.
Dmitriy Ugnichenko
source share