linux下接扫描q问题

linux下接扫描q问题,第1张

linux下接扫描q问题

使用斑马扫描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键值

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5618606.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存