Android (Linux) analog keys, touch screen and other events

Source: Internet
Author: User

Premise:

We often need to simulate the entity keys in our application or when we are writing Android automated tests to test for us. This is what I want to tidy up. The main concerns are the Linux Input event events. The following example is based on Android 5.1 (Linux-3.10).

First, the use of GetEvent, sendevent analog buttons

(1) command: Getevent-t
Results:

...Add Device6:/dev/input/event9 bus:0000Vendor0000Product0000Version0000Name"Msm8994-snd-card button Jack."Location"ALSA"Id:""Version1.0. 1Events:key (0001):0100  0101  0102  0103  0104  0105  0106  0107Input props: <none>... 

We know: the corresponding input event of the headset button we want is event9.

(2) command: Getevent-t/dev/input/event9, use press the headset button to pre-obtain headset event information
Results:

按键按下:0001 00e2 000000010000 0000 00000000松下按键:0001 00e2 000000000000 0000 00000000

(3) using the sendevent command to simulate triggering a line-control key event

sendevent /dev/input/event9 0001 00e2 00000001sendevent /dev/input/event9 0000 0000 00000000**这个之间要延时500ms~1s,不然会被系统误认为是误触发的**sendevent /dev/input/event9 0001 00e2 00000000sendevent /dev/input/event9 0000 0000 00000000

Note: as long as the events of input can be simulated with sendevent, but sometimes it is too much to do with the sliding of analog touch screen, if use sendevent need a lot of command to simulate. This can be replaced by the input command.

Second, using the input command to achieve analog keys, touch screen operation

(1) Analog keys
command: Input keyevent {key value}
The key value of the known Android phone volume + (KEYCODE_VOLUME_UP) is 24, which uses
Input KeyEvent 24 simulates pressing the volume + key. more key values are shown in annex 1.

(2) Analog touch screen operation (Tap, swipe)
command: Input swipe {start point x axis value} {Start point Y axis value} {endpoint X axis value} {end point Y axis value} {sliding time [ignorable]}, Time unit: Ms
For example: from x=100,y=500, slide to x=600,y=500, time 100ms
Input swipe 100 500 600 500 100

command: Input tap {x-axis value} {y-axis value}
For example: Click on the x=100,y=500 point and click the app icon to open the app
Input TAP 100 500

Annex 1






Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android (Linux) analog keys, touch screen and other events

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.