{ Initial import of micy, the minimalistic mouse handler default tip
authorpancake@localhost.localdomain
Wed Apr 29 10:22:42 2009 +0000 (2009-04-29)
changeset 07f88e44e394b
{ Initial import of micy, the minimalistic mouse handler
Makefile
micy.c
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/Makefile	Wed Apr 29 10:22:42 2009 +0000
     1.3 @@ -0,0 +1,3 @@
     1.4 +all: micy.o
     1.5 +	gcc micy.o -o micy
     1.6 +	sudo ./micy | radare -d ls
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/micy.c	Wed Apr 29 10:22:42 2009 +0000
     2.3 @@ -0,0 +1,93 @@
     2.4 +#include <stdio.h>
     2.5 +#include <unistd.h>
     2.6 +#include <stdlib.h>
     2.7 +#include <sys/time.h>
     2.8 +#include <termios.h>
     2.9 +#include <sys/stat.h>
    2.10 +#include <fcntl.h>
    2.11 +#include <sys/types.h>
    2.12 +
    2.13 +int uppercase_mode = 0;
    2.14 +int mouse_mode = 1;
    2.15 +
    2.16 +int mouse(int u, int x, int y)
    2.17 +{
    2.18 +	static int delta = 0;
    2.19 +	if (!mouse_mode)
    2.20 +		return;
    2.21 +	if (uppercase_mode) {
    2.22 +		if (y>3) printf("K\n");
    2.23 +		else if (y<-3) printf("J\n");
    2.24 +	} else {
    2.25 +		//printf("%d:   %d %d\n", u, x, y);
    2.26 +		if (y>2) printf("k\n");
    2.27 +		else if (y<-2) printf("j\n");
    2.28 +		if (x>2) printf("l\n");
    2.29 +		else if (x<-2) printf("h\n");
    2.30 +	}
    2.31 +	fflush(stdout);
    2.32 +}
    2.33 +
    2.34 +// open /dev/tpy and select with stdin to direct write keys or enable/disable mouse
    2.35 +// use micey as a input
    2.36 +// micey -s 4 | radare -d ls
    2.37 +int set_icanon(int fd)
    2.38 +{
    2.39 +	struct termios tc;
    2.40 +	tcgetattr(fd, &tc);
    2.41 +	tc.c_iflag &= ~(BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
    2.42 +//	tc.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
    2.43 +	tc.c_lflag &= ~(ICANON|ISIG|IEXTEN);
    2.44 +	tc.c_cflag &= ~(CSIZE|PARENB);
    2.45 +	tc.c_cflag |= CS8;
    2.46 +	tc.c_cc[VMIN] = 1;
    2.47 +	return tcsetattr(fd, TCSANOW, &tc);
    2.48 +}
    2.49 +
    2.50 +int main(void)
    2.51 +{
    2.52 +	unsigned char ch;
    2.53 +	char buf[3];
    2.54 +	fd_set rfds;
    2.55 +	int tty = 0;
    2.56 +	int ret, tpy;
    2.57 +
    2.58 +	set_icanon(0);
    2.59 +	//printf("pd\nV\n");
    2.60 +	tpy = open("/dev/input/mice", O_RDONLY);
    2.61 +	if (tpy == -1) {
    2.62 +		printf("Cannot open device\n");
    2.63 +		exit(1);
    2.64 +	}
    2.65 +
    2.66 +	printf("b 100\npd\nV\n");
    2.67 +	fflush(stdout);
    2.68 +	while(1)
    2.69 +	{
    2.70 +		FD_ZERO(&rfds);
    2.71 +		FD_SET(0, &rfds);
    2.72 +		FD_SET(tpy, &rfds);
    2.73 +		ret = select(tpy+1, &rfds, NULL, NULL, NULL);
    2.74 +		if (ret == -1)
    2.75 +			break;
    2.76 +		if (ret) {
    2.77 +			if (FD_ISSET(tpy, &rfds)) {
    2.78 +				read(tpy, buf, 3);
    2.79 +				mouse(buf[0], buf[1], buf[2]);
    2.80 +			}
    2.81 +			if (FD_ISSET(0, &rfds)) {
    2.82 +				ret = read(0, &ch, 1);
    2.83 +				switch(ch) {
    2.84 +				case '^':
    2.85 +					mouse_mode ^=1;
    2.86 +					break;
    2.87 +				case '\'':
    2.88 +					uppercase_mode ^= 1;
    2.89 +					break;
    2.90 +				}
    2.91 +				if (ret>0) write(1, &ch, 1);
    2.92 +			}
    2.93 +		}
    2.94 +	}
    2.95 +	return 0;
    2.96 +}