]> git.sesse.net Git - pistorm/blob - input/input.c
Cleanup, move mouse/keyboard input code out of emulator.c
[pistorm] / input / input.c
1 #include <termios.h>
2 #include <unistd.h>
3 #include <linux/input.h>
4
5 int kbhit()
6 {
7   struct termios term;
8   tcgetattr(0, &term);
9
10   struct termios term2 = term;
11   term2.c_lflag &= ~ICANON;
12   tcsetattr(0, TCSANOW, &term2);
13
14   int byteswaiting;
15   ioctl(0, FIONREAD, &byteswaiting);
16
17   tcsetattr(0, TCSANOW, &term);
18
19   return byteswaiting > 0;
20 }
21
22 extern int mouse_fd;
23
24 int get_mouse_status(char *x, char *y, char *b) {
25   struct input_event ie;
26   if (read(mouse_fd, &ie, sizeof(struct input_event)) != -1) {
27     *b = ((char *)&ie)[0];
28     *x = ((char *)&ie)[1];
29     *y = ((char *)&ie)[2];
30     return 1;
31   }
32
33   return 0;
34 }