使用斑马扫描q扫描条形码:6935205322654
在windows 扫描出 :6935205322654
在linux下 读出:
type:1 code:7 value:0
type:1 code:10 value:0
type:1 code:4 value:0
type:1 code:6 value:0
type:1 code:3 value:0
type:1 code:11 value:0
type:1 code:6 value:0
type:1 code:4 value:0
type:1 code:3 value:0
type:1 code:3 value:0
type:1 code:7 value:0
type:1 code:6 value:0
type:1 code:5 value:0
type:1 code:28 value:0
linux 下读取代码:
#include
#include
#include
#include
#define SCANNER_DEV "/dev/input/event2"
struct input_event event;
int fd;
int read_nu;
int main(int argc, char *argv[])
{
fd = open(SCANNER_DEV, O_RDONLY);//打开usb扫描q设备
if (fd < 0)
{
perror("can not open device usbscanner!");
exit(1);
}
int i = 0;
printf("--fd:%d--n",fd);
while(1)
{
if(read(fd,&event,sizeof(struct input_event))>0)
{
switch (event.type)
{
case EV_KEY:
printf("type:%d code:%d value:%dn",event.type,event.code,event.value);
}
}
}
close(fd);
return 1;
}
原因: Linux下键盘键值对应input event下的code值表 不一样。
比如 #define KEY_6 7 此时表示code值为7 对应的键盘值 实际为 6
对应关系 参考链接 Linux下键盘键值对应input event下的code值表_cyf15238622067的博客-CSDN博客_linux键值
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)