Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sys/select.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <X11/Xlib.h>
- #include <X11/Xutil.h>
- #include <X11/Xos.h>
- #include <X11/Xatom.h>
- #include <X11/keysym.h>
- #include <X11/extensions/XTest.h>
- Display *dis;
- Window root;
- typedef struct{
- int tv1;
- int tv2;
- int code;
- int value;
- }event;
- char ch,dn,se,sr;
- unsigned short x,y,sx,sy,mx,my,mxp,myp;
- short dx,dy;
- void move()
- {
- if(se)
- {
- mxp=mx,myp=my;
- mx=(x+sx)/2,my=(y+sy)/2;
- if(sr==0)myp=my,mxp=mx,dx=dy=0,sr=1,XTestFakeButtonEvent(dis,1,0,CurrentTime);
- //if(ch)myp=my,mxp=mx,dx=0,dy=0;
- dx+=mx-mxp,dy+=my-myp;
- //printf("%d %d\n",dx,dy);
- while(abs(dy)>30||abs(dx)>30)
- {
- if(dy>30)
- {
- dy-=30;
- XTestFakeButtonEvent(dis,4,1,CurrentTime);
- XTestFakeButtonEvent(dis,4,0,CurrentTime);
- }
- if(dy<-30)
- {
- dy+=30;
- XTestFakeButtonEvent(dis,5,1,CurrentTime);
- XTestFakeButtonEvent(dis,5,0,CurrentTime);
- }
- if(dx>30)
- {
- dx-=30;
- XTestFakeButtonEvent(dis,6,1,CurrentTime);
- XTestFakeButtonEvent(dis,6,0,CurrentTime);
- }
- if(dx<-30)
- {
- dx+=30;
- XTestFakeButtonEvent(dis,7,1,CurrentTime);
- XTestFakeButtonEvent(dis,7,0,CurrentTime);
- }
- }
- }
- else
- {
- //sr=0;
- XWarpPointer(dis,None,root,0,0,0,0,x,y);
- if(ch)ch=0,XTestFakeButtonEvent(dis,1,dn,CurrentTime);
- }
- XFlush(dis);
- }
- int main()
- {
- fd_set rfds;
- struct timeval tv;
- dis = XOpenDisplay(NULL);
- root=RootWindow(dis,0);
- event* ev;
- ev=calloc(1,16);
- //char down=0,prevdown=0;
- char second;
- char sm;
- unsigned short lx,ly;
- FD_ZERO(&rfds);
- int fd=open("/dev/input/gt82x",O_RDONLY);
- FD_SET(fd,&rfds);
- tv.tv_sec=1;
- tv.tv_usec=0;
- //XEvent xev;
- //memset(0x0,sizeof(xev),&xev);
- //xev.type=ButtornRelease;
- //xev.xbutton.button=1;
- //xev.xbutton.samescreen=True;
- while(1)
- {/*
- if(dn&&!se&&!second&&sm)
- {
- tv.tv_sec=1;
- tv.tv_usec=0;
- FD_ZERO(&rfds);
- FD_SET(fd,&rfds);
- if(select(fd+1,&rfds,NULL,NULL,&tv))
- read(fd,ev,16);
- else
- {
- XTestFakeButtonEvent(dis,1,0,CurrentTime);
- XTestFakeButtonEvent(dis,3,1,CurrentTime);
- XTestFakeButtonEvent(dis,3,0,CurrentTime);
- XFlush(dis);
- printf("g-gurda\n");
- //dn=0,ch=0;
- sm=0;
- FD_SET(fd,&rfds);
- continue;
- }
- }
- else*/ read(fd,ev,16);
- //printf("%d %d %d %d\n",ev->tv1,ev->tv2,ev->code,ev->value);
- switch(ev->code)
- {
- case 131072:if(second==se)move(x,y);break;
- case 3473411:if(second)sx=ev->value*800/800;else x=ev->value*800/800;break;
- case 3538947:if(second)sy=450-ev->value*450/600;else y=450-ev->value*450/600;break;
- case 21626881:ch=1,dn=ev->value,sr=0,sm=dn,lx=x,ly=y;break;
- case 3735555:second=ev->value;break;
- case 0:se=second;if(ch&&dn)lx=x,ly=y;break;
- }
- //if(down!=prevdown){XTestFakeButtonEvent(dis,1,down,CurrentTime);XFlush(dis);}
- //prevdown=down;
- }
- return(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement