日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

【Linux系统编程应用】 Linux输入子系统(二)

發布時間:2024/4/21 linux 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【Linux系统编程应用】 Linux输入子系统(二) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1. 設備ID信息結構體

結構體如下:

/** IOCTLs (0x00 - 0x7f)*/struct input_id {__u16 bustype;__u16 vendor;__u16 product;__u16 version; };struct input_absinfo {__s32 value;__s32 minimum;__s32 maximum;__s32 fuzz;__s32 flat; };
2. 相關ioctl操作

#define EVIOCGVERSION _IOR('E', 0x01, int) /* get driver version */ #define EVIOCGID _IOR('E', 0x02, struct input_id) /* get device ID */ #define EVIOCGREP _IOR('E', 0x03, int[2]) /* get repeat settings */ #define EVIOCSREP _IOW('E', 0x03, int[2]) /* set repeat settings */ #define EVIOCGKEYCODE _IOR('E', 0x04, int[2]) /* get keycode */ #define EVIOCSKEYCODE _IOW('E', 0x04, int[2]) /* set keycode */#define EVIOCGNAME(len) _IOC(_IOC_READ, 'E', 0x06, len) /* get device name */ #define EVIOCGPHYS(len) _IOC(_IOC_READ, 'E', 0x07, len) /* get physical location */ #define EVIOCGUNIQ(len) _IOC(_IOC_READ, 'E', 0x08, len) /* get unique identifier */#define EVIOCGKEY(len) _IOC(_IOC_READ, 'E', 0x18, len) /* get global keystate */ #define EVIOCGLED(len) _IOC(_IOC_READ, 'E', 0x19, len) /* get all LEDs */ #define EVIOCGSND(len) _IOC(_IOC_READ, 'E', 0x1a, len) /* get all sounds status */ #define EVIOCGSW(len) _IOC(_IOC_READ, 'E', 0x1b, len) /* get all switch states */#define EVIOCGBIT(ev,len) _IOC(_IOC_READ, 'E', 0x20 + ev, len) /* get event bits */ #define EVIOCGABS(abs) _IOR('E', 0x40 + abs, struct input_absinfo) /* get abs value/limits */ #define EVIOCSABS(abs) _IOW('E', 0xc0 + abs, struct input_absinfo) /* set abs value/limits */#define EVIOCSFF _IOC(_IOC_WRITE, 'E', 0x80, sizeof(struct ff_effect)) /* send a force effect to a force feedback device */ #define EVIOCRMFF _IOW('E', 0x81, int) /* Erase a force effect */ #define EVIOCGEFFECTS _IOR('E', 0x84, int) /* Report number of effects playable at the same time */#define EVIOCGRAB _IOW('E', 0x90, int) /* Grab/Release device */
3. 相關ID值

/** IDs.*/#define ID_BUS 0 #define ID_VENDOR 1 #define ID_PRODUCT 2 #define ID_VERSION 3#define BUS_PCI 0x01 #define BUS_ISAPNP 0x02 #define BUS_USB 0x03 #define BUS_HIL 0x04 #define BUS_BLUETOOTH 0x05#define BUS_ISA 0x10 #define BUS_I8042 0x11 #define BUS_XTKBD 0x12 #define BUS_RS232 0x13 #define BUS_GAMEPORT 0x14 #define BUS_PARPORT 0x15 #define BUS_AMIGA 0x16 #define BUS_ADB 0x17 #define BUS_I2C 0x18 #define BUS_HOST 0x19 #define BUS_GSC 0x1A
4. 相關ioctl操作示例

參考代碼:

#include <stdio.h> #include <string.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> #include <linux/input.h>#define SIZE 128int main(void) {int ret = -1;int fd = -1;int value;int repeat[2];struct input_id id;char name[SIZE];fd = open("/dev/input/event0", O_RDONLY);if (-1 == fd){perror("open"); goto err0;}//get driver versionvalue = 0;ret = ioctl(fd, EVIOCGVERSION, &value);if (-1 == ret){perror("ioctl"); goto err0;}printf("version: %d\n", value);//get device IDmemset(&id, 0, sizeof(id));ret = ioctl(fd, EVIOCGID, &id);if (-1 == ret){perror("ioctl"); goto err0;}printf("bustype: %hu vendor: %hu product: %hu version: %hu\n", id.bustype, id.vendor, id.product, id.version);//get or set repead memset(repeat, 0, sizeof(repeat)); ret = ioctl(fd, EVIOCGREP, repeat);if (-1 == ret){perror("ioctl"); goto err0;}printf("repeat[0]: %d repeat[1]: %d\n", repeat[0], repeat[1]);//get device nameret = ioctl(fd, EVIOCGNAME(SIZE), name);if (-1 == ret){perror("ioctl"); goto err0;}printf("name: %s\n", name);//get physical locationmemset(name, 0, SIZE);ret = ioctl(fd, EVIOCGPHYS(SIZE), name);if (-1 == ret){perror("ioctl"); goto err0;}printf("physical location: %s\n", name);//get unique identifiermemset(name, 0, SIZE);ret = ioctl(fd, EVIOCGUNIQ(SIZE), name);if (-1 == ret){perror("ioctl"); goto err0;}printf("unique identifier: %s\n", name);close(fd);return 0; err0:return -1; }
執行結果:



參考網址:http://blog.csdn.net/beckdon/article/details/50752128

總結

以上是生活随笔為你收集整理的【Linux系统编程应用】 Linux输入子系统(二)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。