feat: msync(2)
[lunaix-os.git] / lunaix-os / kernel / demos / input_test.c
1 #include <lunaix/input.h>
2
3 #include <ulibc/stdio.h>
4 #include <usr/errno.h>
5 #include <usr/fcntl.h>
6 #include <usr/sys/lunaix.h>
7 #include <usr/unistd.h>
8
9 #define STDIN 1
10 #define STDOUT 0
11
12 void
13 input_test()
14 {
15     int fd = open("/dev/input/i8042-kbd", 0);
16
17     if (fd < 0) {
18         printf("fail to open (%d)", errno);
19         return;
20     }
21
22     struct input_evt_pkt event;
23
24     while (read(fd, &event, sizeof(event)) > 0) {
25         char* action;
26         if (event.pkt_type == PKT_PRESS) {
27             action = "pressed";
28         } else {
29             action = "release";
30         }
31
32         printf("%u: %s '%c', class=0x%x, scan=%x\n",
33                event.timestamp,
34                action,
35                event.sys_code & 0xff,
36                (event.sys_code & 0xff00) >> 8,
37                event.scan_code);
38     }
39     return;
40 }