Browse Source

adding a kbhit() function

phyto 6 months ago
parent
commit
06b5603b8b
3 changed files with 36 additions and 2 deletions
  1. 10
    2
      essai.c
  2. 24
    0
      viz/curses/ecran.c
  3. 2
    0
      viz/curses/ecran.h

+ 10
- 2
essai.c View File

@@ -19,7 +19,7 @@ int	verbosity;
19 19
 /* --------------------------------------------------------------- */
20 20
 int affiche_valeurs(int sfd, int nbloops)
21 21
 {
22
-int		idx, foo;
22
+int		idx, foo, key;
23 23
 char		ligne[200];
24 24
 int		Idatas[4];
25 25
 float		Fdatas[4];
@@ -38,8 +38,16 @@ if (NULL==fp) {
38 38
 
39 39
 for (idx=0; idx<nbloops; idx++) {
40 40
 
41
+	if (kbhit()) {
42
+		message("!!! KEY !!!");
43
+		sleep(2);
44
+		}
45
+
41 46
 	foo = getline_to(sfd, ligne, 100, 0);
42
-	if (verbosity) message(ligne);
47
+
48
+	if (*ligne == 'M') {
49
+		message(ligne);
50
+		}
43 51
 	
44 52
 #if DEBUG_LEVEL
45 53
 	if (foo) fprintf(stderr, "get values -> %d\n", foo);

+ 24
- 0
viz/curses/ecran.c View File

@@ -11,6 +11,30 @@
11 11
 
12 12
 extern int	verbosity;
13 13
 
14
+/* ---------------------------------------------------------------- */
15
+int kbhit(void)
16
+{
17
+int		r, ch;
18
+
19
+nodelay(stdscr, TRUE);
20
+noecho();
21
+
22
+    // check for input
23
+ch = getch();
24
+if( ch == ERR) {     // no input
25
+	r = FALSE;
26
+	}
27
+else	{                // input
28
+	r = TRUE;
29
+	ungetch(ch);
30
+	}
31
+
32
+// restore block and echo
33
+echo();
34
+nodelay(stdscr, FALSE);
35
+
36
+return r;
37
+}
14 38
 /* ---------------------------------------------------------------- */
15 39
 int message(char *txt)
16 40
 {

+ 2
- 0
viz/curses/ecran.h View File

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

Loading…
Cancel
Save