22 #include <utils/system/getkey.h> 23 #include <core/exception.h> 43 oldflags = fcntl(STDIN_FILENO, F_GETFL, 0);
44 oldflags |= O_NONBLOCK;
45 fcntl(STDIN_FILENO, F_SETFL, oldflags);
55 oldflags = fcntl(STDIN_FILENO, F_GETFL, 0);
56 oldflags &= ~O_NONBLOCK;
57 fcntl(STDIN_FILENO, F_SETFL, oldflags);
72 bool blocking = (timeout_decisecs != 0);
73 char buf[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
78 tcgetattr(STDIN_FILENO, &saved_attributes);
80 tcgetattr(STDIN_FILENO, &tattr);
81 tattr.c_lflag &= ~(ICANON);
82 tattr.c_lflag &= ~(ECHO);
83 if (timeout_decisecs < 0) {
86 }
else if (timeout_decisecs > 0) {
88 tattr.c_cc[VTIME]= timeout_decisecs;
93 tcsetattr(STDIN_FILENO, TCSANOW, &tattr);
95 ssize_t read_bytes = read(STDIN_FILENO, buf, 1);
97 tcsetattr(STDIN_FILENO, TCSANOW, &saved_attributes);
100 if (read_bytes == 1) {
103 throw Exception(errno,
"Failed to read key from keyboard (getkey)");
static void set_nonblock_flag()
Set non-blocking flag on STDIN.
Fawkes library namespace.
char getkey(int timeout_decisecs)
Get value of a single key-press non-blocking.
Base class for exceptions in Fawkes.
static void clear_nonblock_flag()
Clear non-blocking flag on STDIN.