嵌入式linux下如何使用usb键盘
2011-12-17 21:55
369 查看
嵌入式linux下如何使用usb键盘
转自:http://rainy0415.blog.163.com/blog/static/168511662010620320385/首先usb键盘驱动的源代码位于一下目录:
drivers/usb/input/usbkbd.c
将usb键盘驱动编译进内核:
#make menuconfig
Device Drivers--->USB support---->USB HIDBP Keyboard (simple Boot) support
(注意:有可能默认设置USB键盘驱动是不可见的,需修改当前目录下的Kconfig文件,在此不做详细介绍,Kconfig语法有待进一步熟悉:))
保存设置后,重新编译内核:
#source setenv
#make uImage
uImage生成后位于目录:arch/arm/boot/uImage;
(或者直接将usb键盘驱动编译为驱动模块,进行加载也可);
启动系统后,确定usb键盘加载到了那个设备文件,一般为/dev/input/event0设备,可通过cat命令进行确认:
#cat /dev/input/event0
操作usb键盘,会有乱码出现;
然后应用层用这个程序来获取usb键盘的输入:
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/input.h>
struct input_event buff;
int fd;
int read_nu;
int main(int argc, char *argv[])
{
fd = open("/dev/input/event0", O_RDONLY);
if (fd < 0)
{
perror("can not open device usbkeyboard!");
exit(1);
}
int i = 0;
printf("--fd:%d--\n",fd);
while(1)
{
while(read(fd,&buff,sizeof(struct input_event))==0)
{
;
}
//if(buff.code > 40)
printf("type:%d code:%d value:%d\n",buff.type,buff.code,buff.value);
//#if 0
//i++;
//if(i > 12)
//{
//break;
//}
//#endif
}
close(fd);
return 1;
}
运行程序后,按下A键,可见如下输出:
--fd:3--
type:1 code:30 value:1
type:0 code:0 value:0
相关文章推荐
- 嵌入式linux下如何使用usb键盘
- 大势至USB管理软件教你如何禁用U盘、屏蔽USB端口而不影响USB鼠标键盘使用!
- 如何禁用U盘又不影响USB键盘的使用
- U盘量产后USB鼠标和键盘都无法使用,如何解决?
- 如何使用UITextFieldDelegate来隐藏键盘?
- 如何使用windows7 USB/DVD Download Tool制作U盘启动
- Ubuntu下如何使用截图工具及自定义键盘快捷键
- 如何在C#中使用全局鼠标、键盘Hook
- 如何使用键盘事件(附Demo)
- 如何在C#中使用全局鼠标、键盘Hook
- linux下如何使用USB存储设备
- 如何使用传统的鼠标和键盘在全新的win8操作系统上使用
- 如何编写Linux下的USB键盘驱动
- 关于如何使用策略禁止USB的问题
- 如何使用USB 或CF卡已启动WES 7(windows embedded stanard 7)
- 系统如何使用键盘快捷关机
- android端和pc端使用usb进行socket通信,其中android是服务器端,pc是客户端。如何实现安卓端输入的数据通过按钮发送到pc端?
- 解决使用USB键盘进行游戏后按任意键出现蓝屏的错误
- 如何在C#中使用全局鼠标、键盘Hook
- 如何在DOS下使用USB设备