title: ADB: How to programmatically determine which input device is used for sending touch event with sendevent
body: <p>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.</p>
  
  <p>Things I've tried:
  <a href="https://stackoverflow.com/questions/39232709/android-programmatically-detect-if-device-has-hardware-touchscreen-connected">Android: Programmatically detect if device has hardware touchscreen connected</a>
  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.</p>
  
  <p>Using <code>dumpsys input</code>. 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.</p>
  
  <p>Using <code>getevent</code> and simulating a tap with <code>input tap &lt;x&gt; &lt;y&gt;</code>. The <code>getevent</code> 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</p>
  
  <pre><code>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
  </code></pre>
  
  <p>However, the <code>input tap &lt;x&gt; &lt;y&gt;</code> command for some reason does not trigger any output on the <code>getevent</code> 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 <code>getevent</code> command would seem to require me to use the <code>sendevent</code> command, but to do so I would already need to know the input device.</p>
  
  <p>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.</p>
  
  <p>Any help with this would be greatly appreciated. Thank you.</p>