1

I am trying to programmatically determine which input device I need to use for sending touch events (i.e. taps, swipes, etc) using adb shell's sendevent command. The adb shell's sendevent expect an input device where it will be sending the event. Example: "adb shell sendevent /dev/input/event4: 0003 0035 000003b4". The issue I am having is that the "event4" portion depends on the device (phone, tablet, etc) being used (it could be "event0", "event1", etc), so, what I am wanting is a way to determine which input device I need to be using for sending touch events.

Things I've tried: Android: Programmatically detect if device has hardware touchscreen connected The suggested answer does not work in all cases since the "Name" field they use is also dependent on the device and may not always include "Touch" and none of the other properties used in that answer seem to correlate with a touch device.

Using dumpsys input. This command gives the different input devices the android device may have, however, again none of the fields seemed to correlate to which one is a touch device.

Using getevent and simulating a tap with input tap <x> <y>. The getevent command also lists the different input devices and when an event is detected, such as a tap, it outputs something very similar to what I am wanting. Example

add device 1: /dev/input/event4
  name:     "Genymotion Virtual Input"
could not get driver version for /dev/input/mouse0, Not a typewriter
add device 2: /dev/input/event3
  name:     "VirtualBox mouse integration"
add device 3: /dev/input/event1
  name:     "Sleep Button"
add device 4: /dev/input/event0
  name:     "Power Button"
add device 5: /dev/input/event2
  name:     "AT Translated Set 2 keyboard"
could not get driver version for /dev/input/mice, Not a typewriter
[    6670.964258] /dev/input/event4: 0001 014a 00000001
[    6670.964258] /dev/input/event4: 0003 003a 00000001
[    6670.964258] /dev/input/event4: 0003 0035 000003b4
[    6670.964258] /dev/input/event4: 0003 0036 000004e2
[    6670.964258] /dev/input/event4: 0000 0002 00000000
[    6670.964258] /dev/input/event4: 0000 0000 00000000
[    6671.027772] /dev/input/event4: 0003 0035 000003b3
[    6671.027772] /dev/input/event4: 0003 0036 000004df
[    6671.027772] /dev/input/event4: 0000 0002 00000000
[    6671.027772] /dev/input/event4: 0000 0000 00000000
[    6671.041099] /dev/input/event4: 0001 014a 00000000
[    6671.041099] /dev/input/event4: 0000 0002 00000000
[    6671.041099] /dev/input/event4: 0000 0000 00000000

However, the input tap <x> <y> command for some reason does not trigger any output on the getevent command (I'm assuming this is expected though I can't find any references that support this). And the only way for me to trigger any of the output on the getevent command would seem to require me to use the sendevent command, but to do so I would already need to know the input device.

Also, this is supposed to not require any intervention of the part of a user, so, they should not need to perform taps or supply the input device themselves. It needs to be fully autonomous.

Any help with this would be greatly appreciated. Thank you.

NCoop
  • 341
  • 3
  • 15
  • 1
    https://stackoverflow.com/a/17263093/1778421 – Alex P. Jan 17 '19 at 14:50
  • Thanks @AlexP. The command they gave didn't fully work for me, however, I was able to make my own parser of the getevent -pl info which worked for me. – NCoop Jan 18 '19 at 01:02

1 Answers1

2

Thanks to @AlexP. for the relevant link to the command getevent -pl. The SO answer he linked did not fully work for me though, so, I had to modify it a bit. This is the one that appears to work for me.

getevent -pl | awk 'BEGIN { RS="add device "; } /^[0-9]/ { print RS $0; }' | grep -B 100 ABS_MT_POSITION_X | awk '/add device/ {print $NF}'

NCoop
  • 341
  • 3
  • 15
  • Some devices do not contain tools like `awk`, `grep`, or `sed`, so, may need to do parsing outside of the adb shell. – NCoop Jan 18 '19 at 01:23