adding a kbhit() function

This commit is contained in:
phyto 2019-05-13 17:48:58 +02:00
parent cce90eb60e
commit 06b5603b8b
3 changed files with 36 additions and 2 deletions

12
essai.c
View File

@ -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<nbloops; idx++) {
if (kbhit()) {
message("!!! KEY !!!");
sleep(2);
}
foo = getline_to(sfd, ligne, 100, 0);
if (verbosity) message(ligne);
if (*ligne == 'M') {
message(ligne);
}
#if DEBUG_LEVEL
if (foo) fprintf(stderr, "get values -> %d\n", foo);

View File

@ -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)
{

View File

@ -2,6 +2,8 @@
* interface ncurses pour dd2 monitoring
*/
int kbhit(void);
int fond_ecran(char *titre);
int message(char *);