Android Test of ADB shell

Source: Internet
Author: User

One, send keyboard events:

Command format 1:adb Shell input keyevent "value"

where value and the corresponding key code are listed in the following table:

KeyEvent Value

KeyCode

Comment

0

Keycode_unknown

1

Keycode_menu

Command fails in SDK2.1 Simulator, sendevent command is possible

2

Keycode_soft_right

3

Keycode_home

4

Keycode_back

5

Keycode_call

6

Keycode_endcall

7

Keycode_0

8

Keycode_1

9

Keycode_2

10

Keycode_3

11

Keycode_4

12

Keycode_5

13

Keycode_6

14

Keycode_7

15

Keycode_8

16

Keycode_9

17

Keycode_star

18

Keycode_pound

19

Keycode_dpad_up

20

Keycode_dpad_down

21st

Keycode_dpad_left

22

Keycode_dpad_right

23

Keycode_dpad_center

24

Keycode_volume_up

25

Keycode_volume_down

26

Keycode_power

27

Keycode_camera

28

Keycode_clear

29

Keycode_a

30

Keycode_b

31

Keycode_c

32

Keycode_d

33

Keycode_e

34

Keycode_f

35

Keycode_g

36

Keycode_h

37

Keycode_i

38

Keycode_j

39

Keycode_k

40

Keycode_l

41

Keycode_m

42

Keycode_n

43

Keycode_o

44

Keycode_p

45

Keycode_q

46

Keycode_r

47

keycode_s

48

keycode_t

49

Keycode_u

50

Keycode_v

51

Keycode_w

52

Keycode_x

53

Keycode_y

54

Keycode_z

55

Keycode_comma

56

Keycode_period

57

Keycode_alt_left

58

Keycode_alt_right

59

Keycode_shift_left

60

Keycode_shift_right

61

Keycode_tab

62

Keycode_space

63

Keycode_sym

64

Keycode_explorer

65

Keycode_envelope

66

Keycode_enter

67

Keycode_del

68

Keycode_grave

69

Keycode_minus

70

Keycode_equals

71

Keycode_left_bracket

72

Keycode_right_bracket

73

Keycode_backslash

74

Keycode_semicolon

75

Keycode_apostrophe

76

Keycode_slash

77

Keycode_at

78

Keycode_num

79

Keycode_headsethook

80

Keycode_focus

81

Keycode_plus

82

Keycode_menu

83

Keycode_notification

84

Keycode_search

85

Tag_last_keycode

Command format 2:adb shell sendevent [device] [type] [code] [value]

For example: adb shell sendevent/dev/input/event0 1 229 1 means press the menu key

ADB Shell Sendevent/dev/input/event0 1 229 0 means Press to release the menu key

Note: The above commands need to be used in combination

The following commands are also known:

Key Name CODE

MENU 229

HOME 102

Back (back button) 158

Call Button 231

End (end call button) 107

Second, send mouse events (Touch):

Command format: adb shell sendevent [device] [type] [code] [value]

1. Touch on a coordinate point

If you touch the x-coordinate of the screen at a point with a 40,y coordinate of 210, the command is as follows

ADB shell sendevent/dev/input/event0 3 0 40

ADB shell sendevent/dev/input/event0 3 1 210

ADB shell sendevent/dev/input/event0 1 1//touch

ADB shell sendevent/dev/input/event0 0 0 0//it must have

adb shell sendevent/dev/input/event0 1 0//untouch

ADB shell sendevent/dev/input/event0 0 0 0//it must have

Note: The above six sets of commands must be used in conjunction with

2. Simulating the sliding trajectory

The following example shows a horizontal line starting at (100,200) and ending with (108,200) on the Apaint software.

ADB shell sendevent/dev/input/event0 3 0//start from point (100,200)

ADB shell sendevent/dev/input/event0 3 1 200

ADB shell sendevent/dev/input/event0 1 1//touch

ADB shell sendevent/dev/input/event0 0 0 0

ADB shell sendevent/dev/input/event0 3 0 101//step to point (101,200)

ADB shell sendevent/dev/input/event0 0 0 0

.....//must list Each step, here just skip, and .....????.

ADB shell sendevent/dev/input/event0 3 0 108//end Point (108,200)

ADB shell sendevent/dev/input/event0 0 0 0

adb shell sendevent/dev/input/event0 1 0//untouch

ADB shell sendevent/dev/input/event0 0 0 0

Iii. cmd instruction python encapsulation 1. Python encapsulation via OS

Adb_shell = "adb shell sendevent/dev/input/event0 3 0" +str (pointx)

Os.system (Adb_shell)

One problem with this approach is that each time a command is executed, a CMD window flashes past, and the following method is used instead.

2. Python encapsulation via subprocess

Adb_shell = "adb shell sendevent/dev/input/event0 3 1" +str (PointX1)

Subprocess. Popen (Adb_shell, stdout=subprocess. PIPE, Shell=true)

This method can avoid the appearance of pop-up windows.

Analog touch differences on the real machine and simulator

Applying the above instructions to the simulator is really effective, but when you move to the real machine, you will find that these instructions have been invalidated and carefully analyzed for two reasons:

1.event

There is only one/dev/input/event0 on the simulator, but it is not on the real machine (if it is true, then you do not leave the Equipment factory-_-| | )。

Use cat to get the event information for your device:

# cat/proc/bus/input/devicesi:bus=0000 vendor=0000 product=0000 version=0000n:name= "Qtouch-touchscreen" P:phys=s: sysfs=/devices/virtual/input/input5u:uniq=h:handlers=event5b:ev=bb:key=400 0 4 0 0 0 0 0 0 0 0b:abs=2750000 11030003 " Qtouch-touchscreen "Not the death of the event several, say 1234567 is possible, look at your device."

2. Touch parameter Data

#探究原因的时候, by:

#adb Shell getevent/dev/input/event5 > GetValue

Can get:

0003 0035 000007c8

0003 0036 00000771

0003 0038 00000001

0000 0002 00000000

0003 0037 00000010

0000 0000 00000000

This is not the same as I imagined the coordinate information, see C, should be 16 binary number, converted into 10 binary can be obtained:

3 53 1992

3 54 1905

3 56 1

0 2 0

3 55 16

0 0 0

Then follow the original method to do a test to verify the results:

ADB Shell SENDEVENT/DEV/INPUT/EVENT5 3 53 1992

ADB Shell sendevent/dev/input/event5 3 54 1905

ADB Shell SENDEVENT/DEV/INPUT/EVENT5 3 56 1

ADB Shell SENDEVENT/DEV/INPUT/EVENT5 0 2 0

ADB Shell SENDEVENT/DEV/INPUT/EVENT5 3 55 16

ADB shell sendevent/dev/input/event5 0 0 0

Results can be achieved by clicking!!

(If the operation of the data is particularly large, then we can use VI, in the script to achieve bulk data conversion: Vim ' +%normal gg ' +., $g/^/s//adb shell sendevent//dev//input//event5/g ' +wq ' Value

Android Test of ADB shell

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.