lib/kinematics/AnalyticalGuess/test/keyboard.cpp
Go to the documentation of this file.
1 #include "keyboard.h"
2 #include <termios.h>
3 #include <unistd.h> // for read()
4 
5 static struct termios initial_settings, new_settings;
6 static int peek_character = -1;
7 
9 {
10  tcgetattr(0,&initial_settings);
11  new_settings = initial_settings;
12  new_settings.c_lflag &= ~ICANON;
13  new_settings.c_lflag &= ~ECHO;
14  new_settings.c_lflag &= ~ISIG;
15  new_settings.c_cc[VMIN] = 1;
16  new_settings.c_cc[VTIME] = 0;
17  tcsetattr(0, TCSANOW, &new_settings);
18 }
19 
21 {
22  tcsetattr(0, TCSANOW, &initial_settings);
23 }
24 
25 int kbhit()
26 {
27 unsigned char ch;
28 int nread;
29 
30  if (peek_character != -1) return 1;
31  new_settings.c_cc[VMIN]=0;
32  tcsetattr(0, TCSANOW, &new_settings);
33  nread = read(0,&ch,1);
34  new_settings.c_cc[VMIN]=1;
35  tcsetattr(0, TCSANOW, &new_settings);
36  if(nread == 1)
37  {
38  peek_character = ch;
39  return 1;
40  }
41  return 0;
42 }
43 
44 int readch()
45 {
46 char ch;
47 
48  if(peek_character != -1)
49  {
50  ch = peek_character;
51  peek_character = -1;
52  return ch;
53  }
54  read(0,&ch,1);
55  return ch;
56 }
57 
58 int _getch() {
59  init_keyboard();
60  kbhit();
61  char c = readch();
63  return c;
64 }
static struct termios initial_settings new_settings


kni
Author(s): Martin Günther
autogenerated on Fri Jun 7 2019 22:06:44