在linux中生成鼠标,键...等事件 [英] Generating mouse,key...etc events in linux

查看:250
本文介绍了在linux中生成鼠标,键...等事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个项目中,我需要编写一个简单的驱动程序,接受来自USB设备的输入,并根据收到的msg(在编写usb鼠标驱动程序,但是使用我自己的协议)对GUI执行操作。
我正在搜索这种可能性,我发现软件测试自动化工具,如LDTP,已经可以生成像鼠标点击和键盘命中的动作。
是否还有其他API可以使用?考虑到我的团队对C语言有很好的了解,没有Linux的经验,消耗多久?

解决方案

你基本上有两个选项,我可以想到:




  • X11:使用XTest扩展( XTestFakeDeviceKeyEvent XTestFakeRelativeMotionEvent 等。)

  • 模块输入。



第一个使用假的输入设备(尝试运行 xinput list在大多数(所有?)X服务器中存在的shell中的。每个调用其中一个 XTestFake * 函数生成一个X输入消息。



第二个是内核模块允许用户应用程序创建输入设备并发送输入事件。您只需打开 / dev / uinput 设备,发送几个 ioctl 来配置它,然后直接写入输入事件。



当然,您可以编写一个输入内核驱动程序!


I am in a project where I will need to write a simple driver that accepts input from a USB device and preforms actions on GUI according to the received msg (Like writing a usb mouse driver but with my own protocol). I am searching the possibility of this and I found software testing automation tools like LDTP that already can generate actions like mouse clicks and keyboard hits . Are there other APIs to use ? How long it will consume given that my team has good understanding of C language and no experience with Linux ?

解决方案

You have basically two options, that I can think of:

  • X11: Use the XTest extension (XTestFakeDeviceKeyEvent, XTestFakeRelativeMotionEvent, etc.)
  • Module uinput.

The first one makes use of fake input devices (try running xinput list in the shell) that are present in most (all?) X servers. Each call to one of the XTestFake* function generates an X input message.

The second one is a kernel module that allows a user application to create input devices and send input events. You simply open the /dev/uinput device, send a few ioctls to configure it, and then write the input events directly.

And, of course, you can write an input kernel driver!

这篇关于在linux中生成鼠标,键...等事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆