1

I am trying to get the (x, y) coordinate of the touch through the pointer location option in Developer Options and I use these coordinates to tap on the screen using sendevent. Here is my script that does the sendevent.

tap.sh sendevent /dev/input/event0 3 57 2421 sendevent /dev/input/event0 3 58 232 sendevent /dev/input/event0 3 53 $1 sendevent /dev/input/event0 3 54 $2 sendevent /dev/input/event0 0 0 0 sendevent /dev/input/event0 3 57 4294967295 sendevent /dev/input/event0 0 0 0

I call the script from adb shell sh tap.sh <x> <y> but it is not tapping on the right coordinate. Instead it is tapping at a different location.

Also when I tap on the screen and check the result in getevent adb shell getevent. I find that the coordinates that is shown on the pointer location and the getevent are different.

Why are they different and how do I solve this issue?

PS: The devices I tried are Nexus 7, Nexus 10.

Naresh Kumar
  • 277
  • 4
  • 18

3 Answers3

6

The X and Y co-ordinates obtained from the getevent and the ones obtained from the pointer location in developer options are not the same. They are mapped using a formula.

displayX = (x - minX) * displayWidth / (maxX - minX + 1)
displayY = (y - minY) * displayHeight / (maxY - minY + 1)

Source: Touch Devices

Giovanni Cappellotto
  • 4,597
  • 1
  • 30
  • 33
Naresh Kumar
  • 277
  • 4
  • 18
  • Do you have any idea, How to get Screen_X and Screen_Y using "adb shell dumpsys input" in latest android version (Q OS , Security patch > feb 2020)? – Jithin Gangadharan Apr 19 '20 at 20:21
  • You can get your displayHeight/Width with dumpsys and min/max x/y values with "adb shell -- getevent -lp /dev/input/eventXXX". Just add your specific event id. – fm611 Nov 19 '20 at 14:07
1

Turn on developer options and enable Pointer Location and you can see the x and y coordinates on top of the screen when you tap on the screen use those coordinates to send tap events.

Tej
  • 564
  • 4
  • 10
0

Are you aware that getevent (in my experience, this possibly varies between devices) shows base 16 values?

(side note: getevent -l is often easier to read as it prints a string representation of the event types)

i.e. if getevent -l says

/dev/input/event1: EV_ABS       ABS_MT_POSITION_X    000001cb       
/dev/input/event1: EV_ABS       ABS_MT_POSITION_Y    00000376

the position of the touch is (459, 886) actually

however it appears that sendevent is not following suit in requiring hex values if your code works at all, as your (such as) 53 and 54 work where I would have used 0035 and 0036.

Edit:

Having tried the original code on a Nexus 5 (correct device file substituted in), I have found that no touch event is generated (nor when the hexadecimal equivalent is substituted, for experimental rigor), nor from reusing values captured (and converted) from getevent. Previously, I have had better experience converting the events with a Python script based on the C one here, and writing the output directly to the device file.

Edit 2:

This question here suggests that the initial code should work.

Alex Skorkin
  • 4,264
  • 3
  • 25
  • 47
jeh
  • 1
  • 1