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:
我正在开发一个android应用程序,需要将触摸事件发送到/dev/input/ eventx。我知道C代码结构做这样的事情如下:
struct input_event {
struct timeval time;
unsigned short type;
unsigned short code;
unsigned int value;
};
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?
要使用这样的代码,我需要设置NDK。相反,我希望使用Runtime.getRunTime来运行等效的linux命令。exec()在android中不需要使用NDK。有什么办法吗?
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.
如果没有,发送事件所需的其余C代码是什么?例如,如何将x=200和y=300处的触摸事件发送给event0?我搜索了一下,没有找到一个明确的解决办法。
Thanks.
谢谢。
1 个解决方案
#1
3
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.
我不清楚为什么需要将事件直接发送到/dev/input/eventX。但是如果它可以通过adb发送,则可以向设备注入许多类型事件。
Try this on your computer:
在你的电脑上试试这个:
adb shell input tap 200 300
adb shell输入tap 200 300
Or this on your android device shell:
或者你的安卓设备外壳:
input tap 200 300
输入利用200 300
But it has a high delay because of outside injection.
但由于外部注射存在较大的延迟。
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)
#1
3
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.
我不清楚为什么需要将事件直接发送到/dev/input/eventX。但是如果它可以通过adb发送,则可以向设备注入许多类型事件。
Try this on your computer:
在你的电脑上试试这个:
adb shell input tap 200 300
adb shell输入tap 200 300
Or this on your android device shell:
或者你的安卓设备外壳:
input tap 200 300
输入利用200 300
But it has a high delay because of outside injection.
但由于外部注射存在较大的延迟。
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)