Android Wireless Test-uidevice app Introduction II

Source: Internet
Author: User

Keys and KeyCode use

First, the phone common keys:

1) Home main screen key

2) Menu key

3) Back key

4) Volume_up volume plus key

5) Volume_down Volume minus button

6) Recentapps recently used app

7) Power supply key

8) Dpad up or down key

9) ...

Second, the key API description:

return value Method name Describe
Boolean Pressbace () Analog Short Press Back button
Boolean Pressdpadcenter () Analog trackball Midpoint button
Boolean Pressdpaddown () Analog trackball down button
Boolean Pressdpadleft () Analog Trackball Left button
Boolean Pressdpadright () Analog Trackball Right button
Boolean Pressdpadup () Analog trackball up button
Boolean Pressdelete () Simulate a short press remove delete button
Boolean Pressenter () Analog Short Press ENTER
Boolean Presshome () Analog Short Press the home button
Boolean Presskeycode (int keycode, int metaState) Analog short Press keyboard code KeyCode
Boolean Presskeycode (int keycode) Analog short Press keyboard code KeyCode
Boolean Pressmenu () Analog short Press the menu key
Boolean Pressrecentapps () Simulate a short press of a recently used program
Boolean Presssearch () Analog Short Press Search key

Example:

 Packagecom.uiautomatortest;ImportAndroid.os.Bundle;Importandroid.os.RemoteException;ImportCom.android.uiautomator.core.UiDevice;Importcom.android.uiautomator.testrunner.UiAutomatorTestCase; Public classTestextendsUiautomatortestcase { Public voidTesthome () {uidevice.getinstance (). Presshome (); Sleep (2000); }         Public voidTestmenu () {uidevice.getinstance (). Pressmenu (); Sleep (2000); }         Public voidTestrecent ()throwsremoteexception{uidevice.getinstance (). Pressrecentapps (); Sleep (2000); }}
Test.java


Three, KeyCode keyboard mapping code:

1) KeyEvent key event

2) META KEY

Auxiliary function keys: ALT, SHIFT, Caps_lock

Column Activation status MetaState
Base Meta_key not activated 0
Caps Shift or CAPS LOCK is activated 1
Fn ALT is activated 2
Caps_fn ALT, SHIFT, or caps LOCK is activated at the same time 3

Example:

 Packagecom.uiautomatortest;ImportAndroid.os.Bundle;Importandroid.os.RemoteException;Importandroid.view.KeyEvent;ImportCom.android.uiautomator.core.UiDevice;Importcom.android.uiautomator.testrunner.UiAutomatorTestCase; Public classTestextendsUiautomatortestcase { Public voidTesthome () {uidevice.getinstance (). Presshome (); Sleep (2000); }         Public voidTestmenu () {uidevice.getinstance (). Pressmenu (); Sleep (2000); }         Public voidTestrecent ()throwsremoteexception{uidevice.getinstance (). Pressrecentapps (); Sleep (2000); }         Public voidTestkeycode () {uidevice.getinstance (). Presskeycode (keyevent.keycode_a);//lowercase aUidevice.getinstance (). Presskeycode (Keyevent.keycode_b);//lowercase bUidevice.getinstance (). Presskeycode (Keyevent.keycode_c);//lowercase cuidevice.getinstance (). Presskeycode (Keyevent.keycode_a,1);//Capital AUidevice.getinstance (). Presskeycode (keyevent.keycode_b,1);//Capital BUidevice.getinstance (). Presskeycode (keyevent.keycode_c,1);//uppercase C            }}
Test.java

Android Wireless Test-uidevice app Introduction II

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.