ADB getevent/sendevent

Source: Internet
Author: User

Getevent & sendevent is a tool in the Android system. It can simulate multiple buttons and touch-screen operations to generate raw events. Raw events are processed by event hub to generate the final gesture events.

It is useful when debugging buttons and touch screens.

 

=== Getevent ===

Getevent monitors the current event, mouse event, button event, drag and slide, etc. after entering the shell, execute getevent to list all input devices and their corresponding names under/dev/input.

The corresponding event will print the corresponding information, such as pressing the key and then touching TP

# Getevent
Getevent
Add device 1:/dev/input/event3
Name: "ft5xxx"
Add device 2:/dev/input/event5
Name: "7k_handset"
Add device 3:/dev/input/event4
Name: "qrd_keypad"
Add Device 4:/dev/input/event2
Name: "proximity"
Add Device 5:/dev/input/event1
Name: "accelerometer"
Add device 6:/dev/input/event0
Name: "orientation"

/Dev/input/event4: 0001 001e 00000001
/Dev/input/event4: 0001 001e 00000000

Where/dev/input/event4 is the device name 0001 is type, 001e is the key code, and the last one varies according to the type
For example, the last one is to press the keydown of key A, and the last one is to press the keyup of key.
The specific definitions of type, code, and value can be found in the source code/frameworks/base/CORE/Java/Android/View/keyevent. java.

 

=== Sendevent ===

 

Command Format 2: ADB shell sendevent [device] [type] [Code] [value]

 

The sending time, in the same format as above. Note that in get, the code is displayed in hexadecimal notation, while in send, the Code must be in decimal notation. For example:

# Sendevent/dev/input/event4 1 5 1
This command is used to send the keydown message of number 4, so many 4 messages are printed on the screen (because keyup is not sent)

PS: this does not work on my mobile phone.

 

For example, ADB shell sendevent/dev/input/event0 1 229 1 means to press the menu key

ADB shell sendevent/dev/input/event0 1 229 0 means to press and release the menu key

Note: The preceding commands must be used in combination.

The command is as follows:

Key name Code

Menu 229

Back home 102

Back (back button) 158

Calls (call button) 231

End (End call button) 107

2. Send a mouse event (touch ):

Command Format: ADB shell sendevent [device] [type] [Code] [value]

Case 1: touch on a coordinate point

For example, if the X coordinate of the screen is 40 and the Y coordinate is 210, run the following command:

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 330 1 // touch
ADB shell sendevent/dev/input/event0 0 0 0 // It must have
  
ADB shell sendevent/dev/input/event0 1 330 0 // untouch
ADB shell sendevent/dev/input/event0 0 0 0 // It must have

Note: The above six groups of commands must be used together.

Scenario 2: simulate a sliding track (download and test with apaint software)

The following example shows a horizontal line starting with (100,200) and ending with (108,200) on apaint.

ADB shell sendevent/dev/input/event0 3 0 100 // start from point (100,200)
ADB shell sendevent/dev/input/event0 3 1 200
  
ADB shell sendevent/dev/input/event0 1 1 330 1 // touch
ADB shell sendevent/dev/input/event0 0 0 0
  
ADB shell sendevent/dev/input/event0 3 0 0 101 // step to point (101,200)
ADB shell sendevent/dev/input/event0 0 0 0
........................ // Must list each step, here just skip
ADB shell sendevent/dev/input/event0 3 0 0 108 // end point (108,200)
ADB shell sendevent/dev/input/event0 0 0 0
  
ADB shell sendevent/dev/input/event0 1 330 0 // untouch
ADB shell sendevent/dev/input/event0 0 0 0

 

 

In addition, you can use Cat to obtain the corresponding event device information.

# Cat/proc/bus/input/devices
CAT/proc/bus/input/devices
I: Bus = 0000 vendor = 0000 Product = 0000 version = 0000
N: Name = "orientation"
P: phys =
S: sysfs =/devices/virtual/input/input0
U: uniq =
H: handlers = event0 cpufreq
B: EV = 9
B: ABS = 100 447

I: Bus = 0018 vendor = 0000 Product = 0000 version = 0000
N: Name = "accelerometer"
P: phys =
S: sysfs =/devices/virtual/input/input1
U: uniq =
H: handlers = event1 cpufreq
B: EV = 9
B: ABS = 7

I: Bus = 0000 vendor = 0000 Product = 0000 version = 0000
N: Name = "proximity"
P: phys =
S: sysfs =/devices/virtual/input/input2
U: uniq =
H: handlers = event2 cpufreq
B: EV = 9
B: ABS = 1, 2000000

I: Bus = 0018 vendor = 0000 Product = 0000 version = 0000
N: Name = "ft5xxx"
P: phys =
S: sysfs =/devices/i2c-0/0-0038/input/input3
U: uniq =
H: handlers = event3 cpufreq
B: EV = B
B: Key = 0
B: ABS = 2650000 3

I: Bus = 0000 vendor = 0000 Product = 0000 version = 0000
N: Name = "qrd_keypad"
P: phys =
S: sysfs =/devices/virtual/input/input4
U: uniq =
H: handlers = KBD event4 cpufreq
B: EV = 3
B: Key = 2000000 0 40000800 c0040 0 0 4

I: Bus = 0000 vendor = 0001 Product = 0001 version = 0001
N: Name = "7k_handset"
P: phys =
S: sysfs =/devices/virtual/input/input5
U: uniq =
H: handlers = KBD event5 cpufreq
B: EV = 23
B: Key = 4 0 0 0 1c0800 0 0 0
B: Sw = 4

#

Input (a powerful tool for developers. It is particularly useful when users often enter their email addresses, passwords, or URLs with long characters)
# Input
Usage: input [text | keyevent]
Input text <string>
Input keyevent <event_code>

 

Refer:

Http://topic.csdn.net/u/20100326/17/1f0fc5a1-3bd2-4294-aa35-1bcb73357aa3.html

Http://www.51testing.com/html/65/n-215865-2.html

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.