Linux 使用uinput创建虚拟input设备
来源:互联网 发布:聂卫平与高层关系 知乎 编辑:程序博客网 时间:2024/04/29 18:20
参考了这里:http://thiemonge.org/getting-started-with-uinput
代码如下:
#include <linux/input.h>#include <linux/uinput.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <unistd.h>#include <string.h>#include <stdint.h>#include <stdio.h>int reportkey(int fd, uint16_t type, uint16_t keycode, int32_t value){int ret;struct input_event ev;memset(&ev, 0, sizeof(struct input_event));ev.type = type;ev.code = keycode;ev.value = value;ret = write(fd, &ev, sizeof(struct input_event));if (ret < 0) {printf("report key error!\n");return ret;}/*printf("key is %d %d\n", keycode, value);*/return 0;}int main(void){struct uinput_user_dev uidev;int fd, ret;fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK);if (fd < 0) {return fd;}ret = ioctl(fd, UI_SET_EVBIT, EV_KEY);ret = ioctl(fd, UI_SET_EVBIT, EV_SYN);ret = ioctl(fd, UI_SET_KEYBIT, KEY_D);memset(&uidev, 0, sizeof(struct uinput_user_dev));snprintf(uidev.name, UINPUT_MAX_NAME_SIZE, "uinput-sample");uidev.id.bustype = BUS_USB;uidev.id.vendor = 0x1234;uidev.id.product = 0xfedc;uidev.id.version = 1;ret = write(fd, &uidev, sizeof(struct uinput_user_dev));ret = ioctl(fd, UI_DEV_CREATE);if (ret < 0) {close(fd);return ret;}while (1) {reportkey(fd, EV_KEY, KEY_D, 1);reportkey(fd, EV_SYN, SYN_REPORT, 0);reportkey(fd, EV_KEY, KEY_D, 0);reportkey(fd, EV_SYN, SYN_REPORT, 0);sleep(1);}ioctl(fd, UI_DEV_DESTROY);close(fd);return 0;}
0 0
- Linux 使用uinput创建虚拟input设备
- Linux使用uinput实现虚拟鼠标
- linux 虚拟输入设备(uinput)模拟鼠标和键盘的使用方法
- 【RFB】Linux uinput 分析,虚拟鼠标,键盘
- 【RFB】Linux uinput 分析,虚拟鼠标,键盘
- Android系统利用uinput设备驱动实现虚拟输入设备
- Android系统利用uinput设备驱动实现虚拟输入设备
- android 使用uinput模拟输入设备
- uinput 用法 android 上层使用uinput 的用法来模拟 input 事件
- linux uinput 分析。
- linux uinput 分析。
- Linux /dev/uinput
- Linux /dev/uinput
- Linux uinput驱动分析
- UInput使用注意事项
- UInput使用注意事项
- uinput的使用
- android 虚拟设备(AVD)的创建和使用
- Dev Express的CheckedListBoxControl全选及遍历方法
- 20140404收盘小结
- Linux进程间通信(三)---管道通信之有名管道及其基础实验
- hdu1005
- [hdu 2006] 求奇数的乘积
- Linux 使用uinput创建虚拟input设备
- 音频编解码·实战篇(1)WAV转至AAC(AAC编码)
- Flex 1152:继承的定义在(命名空间public。。)存在冲突
- TCP/IP协议与UDP协议的区别
- 通过wpa_cli连接一个
- SQL判断一个字段是否是数字的办法
- 开放,有的像雪,浑然一
- 扩展SpringMVC以支持更精准的数据绑定1
- lcx用法之心得总结