android uinput 按键_linux 虚拟输入设备(uinput)模拟鼠标和键盘的使用方法

本文介绍了如何在Linux 2.6.x内核中使用uinput驱动来发送用户输入数据,用于模拟无线游戏手柄、键盘等自定义输入设备。通过加载uinput模块,创建并配置uinput设备,然后利用struct input_event结构向内核发送键盘和鼠标事件,实现自动化脚本中的图形用户输入。
摘要由CSDN通过智能技术生成

Dashboard January 2007 Issue

Mehul Patel

Using uinput driver in Linux-

2.6.x to send user input

Dashboard January 2007 Issue

Using uinput driver in Linux-2.6.x to send user

input

Introduction:

The Linux 2.6.x provides a “uinput” driver, which helps users to inject data to the Linux kernel.

This is very useful while writing applications to interface customized input devices like wireless

joystick, keyboard etc.

The driver uses /dev/uinput device to send data to kernel space which in turn send data to Xwindows

OR active shell. This feature can be used to perform automated shell scripts which

involve graphical user inputs.

Uinput is configured as a loadable module in most of the Linux kernels. You can load uinput

driver by giving the following commands.

$ modprobe uinput

$ lsmod

The “lsmod” command lists all the drivers loaded in the Linux system. You should see “uinput”

driver in the list.

The next step is to develop a sample application. This application will send the user key

sequence to kernel which is in turn sent to X-Windows or shell.

Opening an input device:

// Open the input device

uinp_fd = open("/dev/uinput", O_WRONLY | O_NDELAY);

if (uinp_fd == NULL)

{

printf("Unable to open /dev/uinput/n");

return -1;

}

After opening device you have to configure

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值