linux应用层获取鼠标坐标

    技术2026-05-02  6

    linux应用层获取鼠标坐标 2011-01-13 22:46

    补充:在这个函数中要打开一个鼠标设备,但是在嵌入式的文件系统中没有这个设备节点,鼠标设备的主设备号和次设备号有是如何确定的呢?在  linux 系统中,鼠标和键盘的设备号都是固定的,可以在 PC 上查看,再在嵌入式的文件系统中自己建立。qu@ubuntu:/tmp$ ls -l /dev/input/ total 0drwxr-xr-x 2 root root     120 2008-11-06 08:49 by-pathcrw-rw---- 1 root root 13,  64 2008-11-06 08:49 event0crw-rw---- 1 root root 13,  65 2008-11-06 08:49 event1crw-rw---- 1 root root 13,  66 2008-11-06 08:49 event2crw-rw---- 1 root root 13,  67 2008-11-06 08:49 event3crw-rw---- 1 root root 13,  68 2008-11-06 08:48 event4crw-rw---- 1 root root 13,  69 2008-11-06 08:48 event5crw-rw---- 1 root root 13,  70 2008-11-06 08:48 event6crw-rw---- 1 root root 13,  63 2008-11-06 16:48 micecrw-rw---- 1 root root 13,  32 2008-11-06 16:48 mouse0crw-rw---- 1 root root 13,  33 2008-11-06 08:49 mouse1crw-rw---- 1 root root 13, 128 2008-11-06 08:49 ts0crw-rw---- 1 root root 13, 129 2008-11-06 08:49 ts1鼠标设备一般为  mice  设备,主设备号为  13, 次设备号为  63。键盘设备一般为  event 设备,主设备号为 13, 次设备号为 64 ~ 70。#include <stdio.h>#include <linux/input.h>#include <fcntl.h>#include <sys/time.h>#include <sys/types.h>#include <sys/stat.h>int main(int argc,char **argv){    int fd, retval;    char buf[6];    fd_set readfds;    struct timeval tv;    //fd = open("/dev/input/mice", O_RDONLY);    if(( fd = open("/dev/input/mice", O_RDONLY))<0)    {        printf("Failed to open /"/dev/input/mice/"./n");        exit(1);    }    else    {        printf("open /"/dev/input/mice/" successfuly./n");    }    while(1)    {        tv.tv_sec = 5;        tv.tv_usec = 0;        FD_ZERO(&readfds);        FD_SET(fd, &readfds);        retval = select(fd+1, &readfds, NULL, NULL, &tv);        if(retval==0)            printf("Time out!/n");        if(FD_ISSET(fd,&readfds))        {            if(read(fd, buf, 6) <= 0)//终端设备,一次只能读取一行            {                continue;            }            printf("Button type = %d, X = %d, Y = %d, Z = %d/n", (buf[0] & 0x07), buf[1], buf[2],   buf[3]);        }    }    close(fd);    return 0;}

    最新回复(0)