60 lines
1.1 KiB
C
60 lines
1.1 KiB
C
|
|
||
|
#include <sys/types.h>
|
||
|
#include <sys/event.h>
|
||
|
#include <sys/time.h>
|
||
|
#include <dev/wscons/wsconsio.h>
|
||
|
|
||
|
#include <err.h>
|
||
|
#include <fcntl.h>
|
||
|
#include <poll.h>
|
||
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <unistd.h>
|
||
|
|
||
|
int
|
||
|
main(int argc, char *argv[])
|
||
|
{
|
||
|
struct kevent ev;
|
||
|
char *device;
|
||
|
int fd, kq, kev;
|
||
|
|
||
|
if (argc == 2)
|
||
|
device = argv[1];
|
||
|
else
|
||
|
device = "/dev/wskbd";
|
||
|
|
||
|
fd = open(device, O_RDWR);
|
||
|
if (fd == -1)
|
||
|
err(2, "open %s", device);
|
||
|
|
||
|
if ((kq = kqueue()) <= 0)
|
||
|
err(2, "kqueue");
|
||
|
|
||
|
EV_SET(&ev, fd, EVFILT_DEVICE, EV_ADD | EV_ENABLE | EV_CLEAR,
|
||
|
NOTE_CHG_DATA, 0, NULL);
|
||
|
if (kevent(kq, &ev, 1, NULL, 0, NULL) < 0)
|
||
|
err(2, "kevent init");
|
||
|
|
||
|
while (1) {
|
||
|
#if 0
|
||
|
struct pollfd fds;
|
||
|
int result;
|
||
|
|
||
|
fds.fd = kq;
|
||
|
fds.events = POLLIN;
|
||
|
result = poll(&fds, 1, INFTIM);
|
||
|
printf("poll result %d\n", result);
|
||
|
#endif
|
||
|
kev = kevent(kq, NULL, 0, &ev, 1, NULL);
|
||
|
printf("kevent -> %d\n", kev);
|
||
|
if (kev < 0)
|
||
|
err(2, "kevent");
|
||
|
if (kev /* && ev.fflags & NOTE_CHG_DATA */) {
|
||
|
printf("kevent triggered %lx %hd %hx %x %lld\n",
|
||
|
ev.ident, ev.filter, ev.flags, ev.fflags, ev.data);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return 0;
|
||
|
}
|