在/dev/input/eventX中写入事件需要什么命令? [英] What are the commands needed to write events in /dev/input/eventX?
问题描述
我正在开发一个 android 应用,该应用需要将触摸事件发送到/dev/input/eventX.我知道执行以下操作的C
代码结构如下:
I'm developing an android app that needs to send touch events to /dev/input/eventX. I know the C
code structure to do such a thing is the following:
struct input_event {
struct timeval time;
unsigned short type;
unsigned short code;
unsigned int value;
};
要使用这样的代码,我需要设置 NDK .相反,我想在Android中使用Runtime.getRunTime.exec ()
运行等效的linux
命令,而无需使用NDK.有什么办法吗?
To use such a code, I need to set NDK. Instead, I want to run equivalent linux
commands using Runtime.getRunTime.exec ()
in android without the need to use NDK. Is there any way to do that?
如果否,发送事件所需的其余C
代码是什么?例如,如何将x = 200和y = 300的触摸事件发送到event0?我进行了搜索,但没有找到明确的解决方案.
If no, what are the rest of C
code needed to send an event? For example, how can I send a touch event at x=200 and y=300 to event0? I searched and I didn't find a clear solution.
谢谢.
推荐答案
我不清楚您为什么需要直接向/dev/input/eventX
发送事件.但是,如果它可以通过adb
发送,则可以向设备注入许多类型事件.
I'm not clear about why you need to send event to /dev/input/eventX
directly. But if it can send via adb
, you can inject many type events to device.
在您的计算机上尝试:
adb shell input tap 200 300
或者在您的android设备外壳上:
Or this on your android device shell:
input tap 200 300
但是由于外部注入,它具有很高的延迟.
But it has a high delay because of outside injection.
有关input
命令的更多信息,请参见此处.
More info about input
command see here.
Usage: input [<source>] <command> [<arg>...]
The sources are:
mouse
keyboard
joystick
touchnavigation
touchpad
trackball
stylus
dpad
touchscreen
gamepad
The commands and default sources are:
text <string> (Default: touchscreen)
keyevent [--longpress] <key code number or name> ... (Default: keyboard)
tap <x> <y> (Default: touchscreen)
swipe <x1> <y1> <x2> <y2> [duration(ms)] (Default: touchscreen)
press (Default: trackball)
roll <dx> <dy> (Default: trackball)
这篇关于在/dev/input/eventX中写入事件需要什么命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!