Cannot send touch events to API 10,15 emulators
Hi Diego,
While we did eventually resolve our previous issue (re: clickable elements on API <= 15) we can't seem to actually touch the clickable elements we find. This seems to be because the "tap" option is missing from the input command on at least the API 10 and API 15 emulators. Internet searching suggests the use of the "sendevent" command, although its usage is unclear, since it needs what appear to be device/emulator-specific command codes.
We can get the codes from getevent, but after converting them to decimal and sending them back through setevent, it doesn't seem to work.
Any ideas on how to do touch input programmatically on these versions?
I have made a script for that conversion to use AVC with sendevent touches and added it to adbclient for my specific situation. I am using API 8. I have also shared this with Diego, but the problem is that the events are device specific.
Basicly you need to:
- Determine the correct input device with : "adb shell getevent". Locate the name of the touch screen and observe the line above (this was /dev/input/event0 on my target)
- Check what the max available value is for the ABS event type for device /dev/input/event0 with: "adb shell getevent -p" (this was 4095 for my target)
- Determine the width and height of the touch screen you use. (mine was 800x480)
- Convert the X coordinate : "4095 * ((800 - X) / 800)". Where X is the actual x coordinate you wish to touch.
- Convert the Y coordinate : "4095 * ((480 - Y) / 480)". Where Y is the actual y coordinate you wish to touch.
- when using adb's getevent command and performing a press on the touchscreen the output will contain 8 or more lines. The values are hexadecimal values. "Adb's sendvent" command requires dec values. Therefore all values need to be converted to dec first. (as you figured out)
- The 1st line from getevent marks the touch "DOWN" event .
- The 2nd line's 3rd value is the ABS value for the X coordinate.
- The 3rd line's 3rd value is the ABS value for the Y coordinate.
Therefore only these two lines need to be continuously changed:
sendevent /dev/input/event0 3 53 (converted X coordinate value) sendevent /dev/input/event0 3 54 (converted Y coordinate value)
- the 0 0 0 event marks the end of a touch "DOWN" event.
- the next line marks a touch "RELEASE" event. This usuallually starts with the same SYN and KEY value as the one in step 6. (e.g. 3 48 4 vs 3 48 0)
- the 0 0 0 event marks the end of a touch "RELEASE" event.
In the end you can change the touch function (from adclient) with something like:
if eventType == DOWN:
self.shell(' S="sendevent {}";$S 1 330 1;$S 3 0 {};$S 3 1 {};$S 0 0 0;'.format(dev, x_value, y_value))
if eventType == UP:
self.shell(' S="sendevent {}";$S 1 330 0;$S 3 24 0;$S 0 0 0;'.format(dev))
Let me know if this works for your target.
Thanks Diod, it worked for me on API 10.
The only thing is that I didn't have to do the work around with to convert the X and Y coordinate.
Cheers, Guillermo