Nexus one ignores touch events sent via ADB

2019-06-01 17:46发布

I'm connecting an HTC Nexus One to my PC via USB (using ADB), running Android 2.3.6, with debug mode enabled. Sending individual keys as such, Works!

adb shell input keyevent 82
adb shell input keyevent 20
adb shell input keyevent 20
adb shell input keyevent 22
adb shell input keyevent 22
adb shell input keyevent 22
adb shell input keyevent 66

However, Sending Touch events as such, Fails

adb shell sendevent /dev/input/event3 0003 48 104
adb shell sendevent /dev/input/event3 0003 50 10
adb shell sendevent /dev/input/event3 0003 53 200
adb shell sendevent /dev/input/event3 0003 54 57
adb shell sendevent /dev/input/event3 0000 2 00000000
adb shell sendevent /dev/input/event3 0003 18 47
adb shell sendevent /dev/input/event3 0003 20 00000001
adb shell sendevent /dev/input/event3 0000 0000 00000000
adb shell sendevent /dev/input/event3 0003 48 00000000
adb shell sendevent /dev/input/event3 0003 50 10
adb shell sendevent /dev/input/event3 0003 53 200
adb shell sendevent /dev/input/event3 0003 54 57
adb shell sendevent /dev/input/event3 0000 0002 00000000
adb shell sendevent /dev/input/event3 0003 18 32
adb shell sendevent /dev/input/event3 0003 20 00000000
adb shell sendevent /dev/input/event3 0000 0000 00000000

Here is the output I get from getevents:

add device 1: /dev/input/event6

  name:     "mahimahi-nav"

add device 2: /dev/input/event5

  name:     "mahimahi-keypad"

add device 3: /dev/input/event4

  name:     "proximity"

add device 4: /dev/input/event3

  name:     "synaptics-rmi-touchscreen"

add device 5: /dev/input/event2

  name:     "compass"

add device 6: /dev/input/event1

  name:     "h2w headset"

add device 7: /dev/input/event0

  name:     "lightsensor-level"

Any thoughts or ideas how can I send touch events via ADB ?

2条回答
Fickle 薄情
2楼-- · 2019-06-01 18:08

I think you need to set your X and Y axis touch points and then try to send the events. Also, make sure that you convert this

adb shell sendevent /dev/input/event3 0003 48 104
adb shell sendevent /dev/input/event3 0003 50 10
adb shell sendevent /dev/input/event3 0003 53 200
adb shell sendevent /dev/input/event3 0003 54 57
adb shell sendevent /dev/input/event3 0000 2 00000000

into decimal values like this (as I did only for first line but you will need to do that for all),

adb shell sendevent /dev/input/event3 3 72 260.

For more information, look at this link http://softteco.blogspot.com/2011/03/android-low-level-shell-click-on-screen.html

查看更多
smile是对你的礼貌
3楼-- · 2019-06-01 18:12

I managed to simulate a touch click in Nexus 7 (Android 4.2.0) using the following code:

public static void performClick(int x, int y) {

    try {
        executeCommand("sendevent /dev/input/event0 3 57 21");
        executeCommand("sendevent /dev/input/event0 3 48 9");
        executeCommand("sendevent /dev/input/event0 3 58 182");
        executeCommand("sendevent /dev/input/event0 3 53 " + x);
        executeCommand("sendevent /dev/input/event0 3 54 " + y);
        executeCommand("sendevent /dev/input/event0 0 0 0");
        executeCommand("sendevent /dev/input/event0 3 57 4294967295");
        executeCommand("sendevent /dev/input/event0 0 0 0");

    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (TimeoutException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }       
}

private static void executeCommand(String command) throws InterruptedException, IOException, TimeoutException {
    CommandCapture cmd = new CommandCapture(0, command);
    RootTools.getShell(true).add(cmd).waitForFinish();
}
查看更多
登录 后发表回答