From 06b5603b8bca0c24dfc1ba6524816e31bd9e425e Mon Sep 17 00:00:00 2001 From: phyto Date: Mon, 13 May 2019 17:48:58 +0200 Subject: [PATCH] adding a kbhit() function --- essai.c | 12 ++++++++++-- viz/curses/ecran.c | 24 ++++++++++++++++++++++++ viz/curses/ecran.h | 2 ++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/essai.c b/essai.c index b17a131..1ca1cbf 100644 --- a/essai.c +++ b/essai.c @@ -19,7 +19,7 @@ int verbosity; /* --------------------------------------------------------------- */ int affiche_valeurs(int sfd, int nbloops) { -int idx, foo; +int idx, foo, key; char ligne[200]; int Idatas[4]; float Fdatas[4]; @@ -38,8 +38,16 @@ if (NULL==fp) { for (idx=0; idx %d\n", foo); diff --git a/viz/curses/ecran.c b/viz/curses/ecran.c index 7f72116..71350e1 100644 --- a/viz/curses/ecran.c +++ b/viz/curses/ecran.c @@ -11,6 +11,30 @@ extern int verbosity; +/* ---------------------------------------------------------------- */ +int kbhit(void) +{ +int r, ch; + +nodelay(stdscr, TRUE); +noecho(); + + // check for input +ch = getch(); +if( ch == ERR) { // no input + r = FALSE; + } +else { // input + r = TRUE; + ungetch(ch); + } + +// restore block and echo +echo(); +nodelay(stdscr, FALSE); + +return r; +} /* ---------------------------------------------------------------- */ int message(char *txt) { diff --git a/viz/curses/ecran.h b/viz/curses/ecran.h index 9eded7f..5676cc1 100644 --- a/viz/curses/ecran.h +++ b/viz/curses/ecran.h @@ -2,6 +2,8 @@ * interface ncurses pour dd2 monitoring */ +int kbhit(void); + int fond_ecran(char *titre); int message(char *);