Embed events in Android without root

I tried to figure out how to insert touch / keyboard events into an Android device for a while (inside and outside of your application).

I found an application that does this without root privileges:

https://play.google.com/store/apps/details?id=com.vmlite.vncserver

Does anyone know how they did this?

+4
source share
2 answers

If you want to embed touch events in an Android app without root:

you can use the Instrumentation class, https://developer.android.com/reference/android/app/Instrumentation.html

import android.app.Instrumentation;

public class MainActivity extends Activity {
Instrumentation m_Instrumentation;
  public void onCreate(Bundle savedInstanceState) {
    m_Instrumentation = new Instrumentation();

    int x=0; //your x coord in screen. 
    int y=0; // your y coord in screen. 
    m_Instrumentation.sendPointerSync(MotionEvent.obtain(SystemClock.uptimeMillis(),
                    SystemClock.uptimeMillis(),MotionEvent.ACTION_DOWN,x, y,0));
            m_Instrumentation.sendPointerSync(MotionEvent.obtain(SystemClock.uptimeMillis(),
                    SystemClock.uptimeMillis(),MotionEvent.ACTION_UP,x, y,0));
}
}

This method receives the ACTION_DOWN and ACTION_UP events, which injects the event into the current layout.

: (x, y) , . , , adb.

+3

, Windows Mac USB-, , VMLite Android App Controller, .

, /dev/input/event.. , ( Android- Android). : Part1, Part2

+2

Source: https://habr.com/ru/post/1524303/


All Articles