/* wsmouse events dump */ #include #include #include #include #include #include #include #include void usage(void) { errx(2, "usage: twsmouse [-v version]"); } int main(int argc, char *argv[]) { int ch, fd, n, version = 0; int type, value; char *dev; struct wscons_event event; struct wscons_event_ex eventx; while ((ch = getopt(argc, argv, "v:")) != -1) { switch (ch) { case 'v': version = atoi(optarg); break; default: usage(); } } argc -= optind; argv += optind; if (argc == 1) { dev = argv[0]; } else { dev = "/dev/wsmouse"; } fd = open(dev, O_RDONLY); if (fd < 0) { perror("open"); exit(1); } if (version > 0) if (ioctl(fd, WSKBDIO_SETVERSION, &version) == -1) err(1, "SETVERSION %d", version); while (1) { if (version == 0) n = read(fd, &event, sizeof(struct wscons_event)); else n = read(fd, &eventx, sizeof(struct wscons_event_ex)); if (n <= 0) { perror("read"); } if (version == 0) { type = event.type; value = event.value; } else { type = eventx.type; value = eventx.value; printf("device: %#x: ", eventx.device); } switch (type) { case WSCONS_EVENT_MOUSE_UP: printf("MOUSE_UP: 0x%x\n", value); break; case WSCONS_EVENT_MOUSE_DOWN: printf("MOUSE_DOWN: 0x%x\n", value); break; case WSCONS_EVENT_MOUSE_DELTA_X: printf("MOUSE_DELTA_X: %d\n", value); break; case WSCONS_EVENT_MOUSE_DELTA_Y: printf("MOUSE_DELTA_Y: %d\n", value); break; #ifdef WSCONS_EVENT_MOUSE_DELTA_Z case WSCONS_EVENT_MOUSE_DELTA_Z: printf("MOUSE_DELTA_Z: %d\n", value); break; #endif #ifdef WSCONS_EVENT_MOUSE_ABSOLUTE_Z case WSCONS_EVENT_MOUSE_ABSOLUTE_Z: printf("MOUSE_ABSOLUTE_Z: %d\n", value); break; #endif case WSCONS_EVENT_MOUSE_ABSOLUTE_X: printf("MOUSE_ABSOLUTE_X: %d\n", value); break; case WSCONS_EVENT_MOUSE_ABSOLUTE_Y: printf("MOUSE_ABSOLUTE_Y: %d\n", value); break; case WSCONS_EVENT_MOUSE_DELTA_W: printf("MOUSE_DELTA_W: %d\n", value); break; case WSCONS_EVENT_MOUSE_ABSOLUTE_W: printf("MOUSE_ABSOLUTE_W: %d\n", value); break; case WSCONS_EVENT_SYNC: printf("SYNC\n"); break; case WSCONS_EVENT_HSCROLL: printf("HSCROLL: %d\n", value); break; case WSCONS_EVENT_VSCROLL: printf("VSCROLL: %d\n", value); break; default: printf("unknown event type 0x%x, value 0x%x\n", type, value); } } }