【Linux系统编程应用 Linux输入子系统(二)】蹉跎莫遣韶光老,人生唯有读书好。这篇文章主要讲述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_BUS0
#define ID_VENDOR1
#define ID_PRODUCT2
#define ID_VERSION3
#define BUS_PCI0x01
#define BUS_ISAPNP0x02
#define BUS_USB0x03
#define BUS_HIL0x04
#define BUS_BLUETOOTH0x05
#define BUS_ISA0x10
#define BUS_I80420x11
#define BUS_XTKBD0x12
#define BUS_RS2320x13
#define BUS_GAMEPORT0x14
#define BUS_PARPORT0x15
#define BUS_AMIGA0x16
#define BUS_ADB0x17
#define BUS_I2C0x18
#define BUS_HOST0x19
#define BUS_GSC0x1A
?4. 相关ioctl操作示例?
参考代码:
#include < stdio.h>
#include < string.h>
#include < stdlib.h>
#include < unistd.h>
#include < fcntl.h>
#include < linux/input.h>
#define SIZE 128
int 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 version
value = https://www.songbingjia.com/android/0;
ret = ioctl(fd, EVIOCGVERSION, & value);
if (-1 == ret)
perror("ioctl");
goto err0;
printf("version: %d\\n", value);
//get device ID
memset(& 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 name
ret = ioctl(fd, EVIOCGNAME(SIZE), name);
if (-1 == ret)
perror("ioctl");
goto err0;
printf("name: %s\\n", name);
//get physical location
memset(name, 0, SIZE);
ret = ioctl(fd, EVIOCGPHYS(SIZE), name);
if (-1 == ret)
perror("ioctl");
goto err0;
printf("physical location: %s\\n", name);
//get unique identifier
memset(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;
执行结果:
文章图片
推荐阅读
- # yyds干货盘点 # Pandas入门教程
- Linux系统编程应用 Linux系统中找不到设备/dev/fb0
- BGP 路由协议
- win10系统无法安装打印机怎样办?
- win10系统任务栏不见了如何恢复?
- win10创意者主题怎样下载?
- Win10运行《尼尔机械纪元》全屏有黑边怎样办
- Win10运行《质量效应仙女座》连不上网怎样办?
- Win10系统如何查看并关闭135端口?