|
我参照minigui的ial中的native.c和mou_imps2.c写的imps2鼠标测试程序,按鼠标左键不会马上显示鼠标按下,有时会有,有时没反映,这是为什么?请大家帮忙看看,我用的是usb的3键滚轮鼠标。
以下是源程序
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <fcntl.h>
#include <unistd.h>
#include <semaphore.h>
#include <errno.h>
#include <pthread.h>
#include <string.h>
#include <linux/kd.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
#define MOUSE_WHEEL_UP 0x10
#define MOUSE_WHEEL_DOWN 0x08
#define MOUSE_LEFTBUTTON 0x04
#define MOUSE_MIDDLEBUTTON 0x02
#define MOUSE_RIGHTBUTTON 0x01
static unsigned char buf[5];
static int buttons[4] = { 0, 4, 1, 5};
static int nbytes=0;
static unsigned char IMPS2_Param [] = {243,200,243,100,243,80};
int main(int argc,char **argv)
{
int nDeviceFD;
fd_set readfds;
int e;
int n;
int nOldButton = 0;
int nButton = 0;
struct timeval eventTimeout;
eventTimeout.tv_sec = 0;
eventTimeout.tv_usec = 300000;
nDeviceFD = open ("/dev/mouse", O_RDWR | O_NONBLOCK);
if(nDeviceFD<0)
{
printf("Open /dev/mouse failed %d!\n",nDeviceFD);
return 0;
}
else
{
printf("Open /dev/mouse success %d!\n",nDeviceFD);
write (nDeviceFD, IMPS2_Param, sizeof (IMPS2_Param));
}
while(1)
{
FD_ZERO(&readfds);
FD_SET(nDeviceFD, &readfds);
e = select (FD_SETSIZE, &readfds, NULL, NULL, &eventTimeout) ;
if (e > 0)
{
if( FD_ISSET (nDeviceFD, &readfds))
{
FD_CLR (nDeviceFD, &readfds);
while ((n = read (nDeviceFD, &buf [nbytes], 4 - nbytes)))
{
//printf("Read imps2 end %d\n",n);
if (n < 0)
{
if (errno == EINTR || errno == EAGAIN)
{
continue;
}
else
{
printf("Read imps2 failed n=%d errno=%d\n",n,errno);
return -1;
}
}
nbytes += n;
if (nbytes == 4)
{
if ((buf[0] & 0xc0) != 0)
{
buf[0] = buf[1];
buf[1] = buf[2];
buf[2] = buf[3];
nbytes = 3;
break;
}
nButton = buttons[(buf[0] & 0x03)];
nbytes = 0;
if(nButton & MOUSE_LEFTBUTTON)
{
printf("D!D!D!_\n");
}
if(nOldButton==nButton)
{
printf("WM_MOUSEMOVE \n");
}
else if(!(nOldButton & MOUSE_LEFTBUTTON) && (nButton & MOUSE_LEFTBUTTON) )
{
printf("WM_LBUTTONDOWN\n");
}
else if ((nOldButton & MOUSE_LEFTBUTTON) && !(nButton & MOUSE_LEFTBUTTON) )
{
printf("WM_LBUTTONUP\n");
}
nOldButton = nButton;
break;
}
}
}
}
else if(e==0)
{
//printf("select outtime\n");
}
else
{
printf("select error\n");
return 0;
}
}
return 0;
} |
|