Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
KNI_4.3.0
lib
kinematics
AnalyticalGuess
test
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
8
void
init_keyboard
()
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
20
void
close_keyboard
()
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
();
62
close_keyboard
();
63
return
c;
64
}
close_keyboard
void close_keyboard()
Definition:
lib/kinematics/AnalyticalGuess/test/keyboard.cpp:20
new_settings
static struct termios initial_settings new_settings
Definition:
lib/kinematics/AnalyticalGuess/test/keyboard.cpp:5
kbhit
int kbhit()
Definition:
lib/kinematics/AnalyticalGuess/test/keyboard.cpp:25
peek_character
static int peek_character
Definition:
lib/kinematics/AnalyticalGuess/test/keyboard.cpp:6
keyboard.h
init_keyboard
void init_keyboard()
Definition:
lib/kinematics/AnalyticalGuess/test/keyboard.cpp:8
_getch
int _getch()
Definition:
lib/kinematics/AnalyticalGuess/test/keyboard.cpp:58
readch
int readch()
Definition:
lib/kinematics/AnalyticalGuess/test/keyboard.cpp:44
kni
Author(s): Martin Günther
autogenerated on Fri Jan 3 2020 04:01:16