## 1. Get the coordinate position of the tap screen

by

Command to get the location coordinates of the click screen:

Step 1: Calculate the ratio

First pass the command

adb shell getevent -p | grep -e "0035" -e "0036"

Obtain the width (0035) and height (0036) in the event system

Taking the mobile phone I currently use as an example, the command outputs the following information:

0035  : value 0, min 0, max 1602, fuzz 0, flat 0, resolution 0
0036  : value 0, min 0, max 2503, fuzz 0, flat 0, resolution 0

Note: If it is a windows environment, there is no "|" pipe and grep command, you can use it directly

Then filter the 0035 and 0036 in the printed information to find the corresponding two lines of information

All we need is the max

0035 (width) max 1602

0036 (high) max 2503

The resolution of the mobile phone screen is known, and the current mobile phone I use as an example

The screen resolution of the mobile phone is 1080p, namely: 1080 (wide) * 1920 (high)

Calculate the ratio:

rateW = 1080 (the width of the phone screen) / 1602 (max of 0035 in the event) = 0.674

rateH = 1920 (the height of the phone screen) / 2503 (max of 0036 in the event) = 0.767

Step 2: Click the screen to calculate the coordinates of the click location

Excuting an order

adb shell getevent | grep -e "0035" -e "0036"

Taking the mobile phone I currently use as an example, the command outputs the following information:

/dev/input/event0: 0003 0035 00000341
/dev/input/event0: 0003 0036 000008ec

width = 0x341 = 3*16*16 + 4*16 + 1 = 833

height = 0x8ec = 8*16*16 + 14*16 + 12 = 2284

screenW = width*rateW = 833*0.674 = 561

screenH = height*rateH = 2284*0.767 = 1751

==============================================================================

## 2. 模拟滑动、点击屏幕事件

usage: input ...

input text <string>
input keyevent <key code number or name>
input tap <x> <y>
input swipe <x1> <y1> <x2> <y2>

1. keyevent指的是Android对应的keycode，比如home键的keycode=3，back键的keycode=4.

2. 关于tap的话，他模拟的是touch屏幕的事件，只需给出x、y坐标即可。

adb shell input tap 250 250

3. 关于swipe同tap是一样的，只是他是模拟滑动的事件，给出起点和终点的坐标即可。例如从屏幕(250, 250), 到屏幕(300, 300)即

adb shell input swipe 250 250 300 300

### Guess you like

Origin blog.csdn.net/beyond702/article/details/69258932
Recommended
Ranking
Daily