获取输入设备的vid和pid

一、获取/dev/input/event16设备的vid和pid

testhid.c

  1. #include <linux/types.h>  
  2. #include <linux/input.h>  
  3. #include <linux/hidraw.h>  
  4.   
  5. #include <sys/ioctl.h>  
  6. #include <sys/types.h>  
  7. #include <sys/stat.h>  
  8. #include <fcntl.h>  
  9. #include <unistd.h>  
  10. #include <poll.h>  
  11. #include <time.h>  
  12. #include <math.h>  
  13.   
  14. #include <stdio.h>  
  15. #include <stdint.h>  
  16. #include <string.h>  
  17. #include <stdlib.h>  
  18. #include <errno.h>  
  19. int main(){  
  20.   char filename[64];  
  21.   strcpy(filename,"/dev/input/event16");  
  22.   char name[80];  
  23.   int fd = open(filename, O_RDWR /*| O_NONBLOCK*/);  
  24.   if(fd <= 0) {  
  25.     printf("TK----------->>>>open error\n");  
  26.     return -1;  
  27.   }  
  28.   /  
  29.   struct input_id inputId;  
  30.   int rc = ioctl(fd, EVIOCGID, &inputId);  
  31.   printf("TK-------->>>>info.vendor is 0x%x\n",inputId.vendor);  
  32.   printf("TK-------->>>>info.product is 0x%x\n",inputId.product);  
  33.   printf("TK-------->>>>info.bustype is 0x%x\n",inputId.bustype);  
  34.   /* 
  35.   struct hidraw_devinfo info; 
  36.   int rc = ioctl(fd, HIDIOCGRAWINFO, &info); 
  37.   printf("TK-------->>>>info.vendor is 0x%x\n",info.vendor); 
  38.   printf("TK-------->>>>info.product is 0x%x\n",info.product); 
  39.   printf("TK-------->>>>info.bustype is 0x%x\n",info.bustype); 
  40.   */  
  41.   ///  
  42.   struct hidraw_report_descriptor descriptor;  
  43.   rc = ioctl(fd, HIDIOCGRDESC, &descriptor);  
  44.   printf("TK-------->>>>descriptor.size is 0x%04x\n",descriptor.size);  
  45.   //  
  46.   int descriptorSize=0;  
  47.   rc = ioctl(fd, HIDIOCGRDESCSIZE, &descriptorSize);  
  48.   printf("TK-------->>>>descriptorSize is 0x%04x\n",descriptorSize);    
  49.   //  
  50.   name[sizeof(name) - 1] = '\0';  
  51.   if(ioctl(fd, EVIOCGNAME(sizeof(name) - 1), &name) < 1) {  
  52.     name[0] = '\0';  
  53.   }  
  54.   printf("TK------->>>name is %s\n",name);  
  55.   //  
  56.   close(fd);  
  57.   return 0;  
  58. }  

二、编译

Android.mk

[plain] view plain copy 在CODE上查看代码片派生到我的代码片
  1. LOCAL_PATH:= $(call my-dir)  
  2. include $(CLEAR_VARS)  
  3.   
  4. LOCAL_SRC_FILES:= \  
  5.     testhid.c  
  6.   
  7. LOCAL_SHARED_LIBRARIES := \  
  8.     libutils   
  9.   
  10. LOCAL_MODULE:= testinput  
  11.   
  12. LOCAL_MODULE_TAGS := optional  
  13.   
  14. include $(BUILD_EXECUTABLE)  

三、运行

[plain] view plain copy 在CODE上查看代码片派生到我的代码片
    1. TK-------->>>>info.vendor is 0x0  
    2. TK-------->>>>info.product is 0x1  
    3. TK-------->>>>info.bustype is 0x19  
    4. TK-------->>>>descriptor.size is 0x0000  
    5. TK-------->>>>descriptorSize is 0x0000  
    6. TK------->>>name is Power Button 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值