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