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.