DFNgen  2.0
DFN Model Generator
hotkey.cpp
Go to the documentation of this file.
1 #include <stdlib.h>
2 #include <string.h>
3 #include <unistd.h>
4 #include <sys/select.h>
5 #include <termios.h>
6 #include "hotkey.h"
7 
8 //WARNING: NEEDS ERROR HANDLING
9 
10 /***********************************************/
13 {
14  // load original terminal settings
15  tcsetattr(0, TCSANOW, &orig_termios);
16 }
17 
18 
19 /***********************************************/
24 {
25  struct termios new_termios;
26 
27  /* take two copies - one for now, one for later */
28  tcgetattr(0, &orig_termios);
29  memcpy(&new_termios, &orig_termios, sizeof(new_termios));
30 
31  /* register cleanup handler, and set the new terminal mode */
32  new_termios.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
33  new_termios.c_oflag |= ONLCR;
34  new_termios.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
35  new_termios.c_cflag &= ~(CSIZE | PARENB);
36  new_termios.c_cflag |= CS8;
37  tcsetattr(0, TCSANOW, &new_termios);
38 }
39 
40 
41 /***********************************************/
44 int kbhit()
45 {
46  struct timeval tv = { 0L, 0L };
47  fd_set fds;
48  FD_ZERO(&fds);
49  FD_SET(0, &fds);
50  return select(1, &fds, NULL, NULL, &tv);
51 }
52 
53 
54 /***********************************************/
57 int getch()
58 {
59  int r;
60  unsigned char c;
61  if ((r = read(0, &c, sizeof(c))) < 0) {
62  return r;
63  } else {
64  return c;
65  }
66 }
67 
68 
void reset_terminal_mode()
Definition: hotkey.cpp:12
void set_conio_terminal_mode()
Definition: hotkey.cpp:23
int getch()
Definition: hotkey.cpp:57
struct termios orig_termios
Definition: DFNmain.cpp:36
int kbhit()
Definition: hotkey.cpp:44