android - 如何直接发送触摸事件到/dev/input/event?

标签 android linux linux-kernel touchscreen

我想在整个Android系统中发送触摸事件。我正在从后台服务发送事件。我的设备已获得 root 权限,并且我已将我的应用程序存储在/system/app 中。

我尝试了检测和system/bin/input选项卡,检测在应用程序之外不起作用,第二个不会生成错误,但什么也不做。我尝试直接注入(inject)到/dev/input/event2,但没有效果。

代码如下:

 Thread t = new Thread(new Runnable() {
    @Override
    public void run() {




               try {
                    Process process = Runtime.getRuntime().exec("su");//supolicy --live \"allow appdomain input_device dir { ioctl read getattr search open }\" \"allow appdomain input_device chr_file { ioctl read write getattr lock append open }\"");
                    Runtime.getRuntime().exec ("su chmod 666 /dev/input/event2");
                   DataOutputStream os = new DataOutputStream(process.getOutputStream());
                    String cmd = "su /dev/input/event2  ABS_X "+  xPos + " ABS_Y "+ yPos+ "\n";

                    Runtime.getRuntime().exec(cmd);
                }
                catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });

        t.start();

我使用这个网站作为引用:https://yhcting.wordpress.com/2010/11/29/linux-writing-input-event-directly/ ,但我不确定我是否正确应用它。如何在/dev/input/event2 中注入(inject)事件?

另外,/dev/input/eventX 是什么?我总是看到它,但不清楚它是输入节点还是只是事件节点的一般指示。最后,我如何知道应该将事件发送到哪个事件节点(event1、event2等)?

编辑:我尝试通过 adb shell su/dev/input/event2 ABS_X xPos ABS_Y yPos 我收到一行内容:未知的用户名或 uid,这是什么意思?

谢谢。

最佳答案

“input”只是android系统中的一个sh脚本。

# Script to start "input" on the device, which has a very rudimentary
# shell.
#
base=/system
export CLASSPATH=$base/framework/input.jar
exec app_process $base/bin com.android.commands.input.Input $*

可以在此处找到有关如何实现“输入”的 Java 代码跟踪:

http://www.srcmap.org/sd_share/4/aba57bc6/AOSP_adb_shell_input_Code_Trace.html

您还可以使用“sendevent”直接注入(inject)触摸事件 input/dev/input/event0

http://ktnr74.blogspot.com/2013/06/emulating-touchscreen-interaction-with.html

关于android - 如何直接发送触摸事件到/dev/input/event?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36342330/

相关文章:

c - ptrace(),如何停止在子进程中被跟踪?

linux - 在 Linux 上以递归方式对特定文件类型进行 grep

linux - 是否可以从 stdin、stdout、stderr 以外的 fd 重定向输入/输出

java - 构建发布版本的签名 APK 失败,但调试成功。缺课

java - Android中如何确定两个 View 的公共(public)父 View

java - 列表中的 EditText 未按应有的方式工作

c++ - 用户空间(Linux)中是否有任何高分辨率时钟(us)?

c - 无法理解 Linux 内核模块中 read_proc 的工作

linux - linux 挂起/唤醒如何为 mach-omap2 工作?

java - IO异常 : closed failed on FileOutputStream