读书人

uClinux停应用程序获取USB键值

发布时间: 2013-04-05 10:24:33 作者: rapoo

uClinux下应用程序获取USB键值

[ 注:内核代码中Documentation/input/input.txt,有输入设备的介绍。]

系统检测到USB键盘后,一般会将其映射到/dev/input/event0,可能使用cat命令进行确认:

#cat /dev/input/event0

操作USB键盘时会有乱码出现。

也可以用以下命令查看设备与节点的关联:

#cat /proc/bus/input/devices

我的系统接入一块罗技的USB键盘,输出以下信息:

#include <unistd.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <stdio.h>#include <linux/input.h>struct input_event buf;int main(int argc, char **argv){    int fd;    int nread;    fd = open("/dev/input/event0", O_RDONLY);    if (fd < 0)    {        printf("fail to open usbdev.\n");        exit(1);    }    printf("--fd = %d--\n", fd);    while (1)    {        nread = read(fd, &buf, sizeof(buf));        if (nread != 0)        {            printf("type : %d, code = %d, value = %d\n",                    buf.type, buf.code, buf.value);        }    }    return 0;}


读书人网 >UNIXLINUX

热点推荐