模拟鼠标事件的处理
时间:2011-01-04 来源:willwwei
板子上的USB接口坏掉了,为了重现有鼠标时的状态,现做一个模拟鼠标:
input.h
usbmouse.h
struct mouse_my g_mt;
int mouse_state;
#define BUFFER 800
#define SERV_PORT 7838 void *read_uart_mouse(void *para)
{
int sockfd;
//socklen_t len;
socklen_t src_len;
struct sockaddr_in servaddr, cliaddr;
char msg[BUFFER];
sockfd = socket(AF_INET, SOCK_DGRAM, 0); /* create a socket */
/* init servaddr */
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
servaddr.sin_port = htons(SERV_PORT); /* bind address and port to socket */
if(bind(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) == -1)
{
perror("bind error");
}
src_len = sizeof(cliaddr);
while(1)
{
if(recvfrom(sockfd, msg, BUFFER, 0, (struct sockaddr *)&cliaddr, &src_len)< 0)
{
perror("receive error!\n"); }else{
mouse_state = 1;
memcpy(&g_mt,msg,sizeof(struct mouse_my));
memset(msg,0,sizeof(msg));
}
} }
找到鼠标事件的处理处:
int mouse_state;
#define BUFFER 800
#define SERV_PORT 7838 void *read_uart_mouse(void *para)
{
int sockfd;
//socklen_t len;
socklen_t src_len;
struct sockaddr_in servaddr, cliaddr;
char msg[BUFFER];
sockfd = socket(AF_INET, SOCK_DGRAM, 0); /* create a socket */
/* init servaddr */
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
servaddr.sin_port = htons(SERV_PORT); /* bind address and port to socket */
if(bind(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) == -1)
{
perror("bind error");
}
src_len = sizeof(cliaddr);
while(1)
{
if(recvfrom(sockfd, msg, BUFFER, 0, (struct sockaddr *)&cliaddr, &src_len)< 0)
{
perror("receive error!\n"); }else{
mouse_state = 1;
memcpy(&g_mt,msg,sizeof(struct mouse_my));
memset(msg,0,sizeof(msg));
}
} }
找到鼠标事件的处理处:
相关阅读 更多 +