#includevoidmain(intargc,char**argv)
{
fd_setreadset;
Gpm_Eventevent;
Gpm_Connectconn;
conn.eventMask=~0;
conn.defaultMask=~GPM_HARD;
conn.maxMod=0;
conn.minMod=0;
if(Gpm_Open(&conn,0)==-1){
printf("Cannotopenmouseconnectionn");
exit(1);
}
while(1){
FD_ZERO(&readset);
FD_SET(gpm_fd,&readset);
select(gpm_fd+1,&readset,0,0,0);
if(FD_ISSET(gpm_fd,&readset)){
if(Gpm_GetEvent(&event)>0){
printf("mouse:event0x%02X,at%2i%2i(delta%2i%2i),"
"button%i,modifiers0x%02Xrn",
event.type,
event.x,event.y,
event.dx,event.dy,
event.buttons,
event.modifiers
);
}
}
}
while(Gpm_Close());
}
编译
gcc-ogpm_mousegpm_mouse.c-lgpm
检验结果
mouse:event0x01,at151(delta-2-1),button0,modifiers0x00
mouse:event0x01,at141(delta-10),button0,modifiers0x00
mouse:event0x01,at131(delta-10),button0,modifiers0x00
资料结构
typedefstructGpm_Connect{
unsignedshorteventMask,defaultMask;
unsignedshortminMod,maxMod;
intpid;
intvc;
}Gpm_Connect;
enumGpm_Etype{
GPM_MOVE=1,
GPM_DRAG=2,/*exactlyoneofthebareonesisactiveatatime
*/
GPM_DOWN=4,
GPM_UP=8,
GPM_SINGLE=16,/*atmostoneinthreeisset*/
GPM_DOUBLE=32,
GPM_TRIPLE=64,/*WARNING:Idependonthevalues*/
GPM_MFLAG=128,/*motionduringclick?*/
GPM_HARD=256,/*ifsetinthedefaultMask,forcean
alreadyusedeventtopassovertoanotherhandler*/
GPM_ENTER=512,/*enterevent,userinRoi's*/
GPM_LEAVE=1024/*leaveevent,usedinRoi's*/
};
typedefstructGpm_Event{
unsignedcharbuttons,modifiers;/*trytobeamultipleof4*/
unsignedshortvc;
shortdx,dy,x,y;
enumGpm_Etypetype;
intclicks;
enumGpm_Marginmargin;
}Gpm_Event;
typedefintGpm_Handler(Gpm_Event*event,void*clientdata);
函数宣告
intGpm_Open(Gpm_Connect*CONN,intFLAGS);
intGpm_Close(void);
intGpm_GetEvent(Gpm_Event*EVENT);
intGpm_Getc(FILE*fp);
#defineGpm_Getchar()Gpm_Getc(stdin)
intGpm_Wgetch();
#defineGpm_Getch()(Gpm_Wgetch(NULL))
intGpm_Repeat(intmillisecs);
intGpm_DrawPointer(intX,intY,intFD);
intGPM_DRAWPOINTER(Gpm_Event*EPTR;)
intGpm_FitValuesM(int*X,int*Y,intMARGIN);
intGpm_FitValues(X,Y);
Gpm_FitEvent(EPTR);
char*Gpm_GetLibVersion(int*where);
char*Gpm_GetServerVersion(int*where);
intGpm_GetSnapshot(Gpm_Event*ePtr);