#include <sys/types.h>
#include <sys/time.h>
#include <dev/wscons/wsconsio.h>
#include <stdio.h>

main()
{
	int fd, nread;
	unsigned type;
	struct wscons_event ev;

	fd = open("/dev/wsmouse0", 2);
	if (fd < 0) {
		perror("/dev/wsmouse0");
		exit(1);
	}
	if (ioctl(fd, WSMOUSEIO_GTYPE, &type) < 0) {
		perror("WSMOUSEIO_GTYPE");
		exit(1);
	}
	printf("mouse type = %d\n", type);
	while ((nread = read(fd, &ev, sizeof(ev))) > 0) {
		switch (ev.type) {
		case WSCONS_EVENT_MOUSE_DOWN:
			fprintf(stderr, "%c", "LMR"[ev.value & 03]);
			break;
		case WSCONS_EVENT_MOUSE_UP:
			fprintf(stderr, "%c", "lmr"[ev.value & 03]);
			break;
		default:
			fprintf(stderr, ".");
		}
	}
	if (nread < 0)
		perror("read");
	exit(0);
}
