Simulating Keyboard Events in Android

前端 未结 2 606
闹比i
闹比i 2021-01-27 18:50

I have a project and I am trying to fire Keyboard events. I am using the Instrumentation Class, and it is working perfectly on the emulator, but when I launch it on my device, t

2条回答
  •  再見小時候
    2021-01-27 19:42

    In instrumentation, there is the api to send keycode:

    getInstrumentation().sendCharacterSync(int keycode);
    

    If you have root access to the device, you can check the code here:

    https://code.google.com/p/androidscreencast/source/browse/AndroidScreencastClient/src/net/srcz/android/screencast/client/ClientHandler.java ;
    

    to use IWindowManager. The IWindowManager is apart of android system, you can find the class in android.jar, the source code can be downloaded from android official website.

提交回复
热议问题