adb shell中模拟键盘鼠标事件
openharmony模拟按键的方法
![openharmony模拟按键的方法](https://img.taocdn.com/s3/m/9b90071976232f60ddccda38376baf1ffd4fe313.png)
一、概述在使用开放原子系统时,我们经常需要模拟按键来控制设备或应用程序。
本文将介绍在openharmony系统中模拟按键的方法,帮助开发者更好地使用openharmony系统。
二、使用sendevent命令模拟按键1. 使用sendevent命令可以模拟按键事件,该命令可以在终端或通过adb shell执行。
2. sendevent命令需要知道设备的输入设备路径、事件类型、事件代码以及事件值。
3. 首先需要查找设备的输入设备路径,可以通过命令“cat/proc/bus/input/devices”来查看。
4. 然后使用sendevent命令模拟按键事件,例如模拟点击HOME键可以使用如下命令:```shellsendevent /dev/input/event0 1 172 1sendevent /dev/input/event0 0 0 0sendevent /dev/input/event0 1 172 0sendevent /dev/input/event0 0 0 0```其中,第一列是事件类型,第二列是事件代码,第三列是事件值。
三、使用input命令模拟按键1. 在openharmony系统中,也可以使用input命令来模拟按键事件,该命令更加简洁易用。
2. input命令格式为“input keyevent <event_code>”,其中event_code为按键事件的代码。
3. 模拟点击HOME键可以使用如下命令:```shellinput keyevent 3```四、使用C/C++代码模拟按键1. 在openharmony系统中,也可以通过C/C++代码来模拟按键事件。
2. 首先需要获取设备的输入设备文件描述符,可以通过open函数来打开输入设备。
3. 然后通过write函数向输入设备写入事件数据,模拟按键事件。
4. 代码示例:```c#include <tl.h>#include <linux/input.h>int fd;struct input_event event;fd = open("/dev/input/event0", O_RDWR);if (fd < 0) {perror("open input device"); return -1;}event.type = EV_KEY;event.code = KEY_HOME;event.value = 1;write(fd, event, sizeof(event));event.type = EV_SYN;event.code = SYN_REPORT; event.value = 0;write(fd, event, sizeof(event));event.type = EV_KEY;event.code = KEY_HOME;event.value = 0;write(fd, event, sizeof(event));event.type = EV_SYN;event.code = SYN_REPORT; event.value = 0;write(fd, event, sizeof(event));close(fd);```五、总结本文介绍了在openharmony系统中模拟按键的几种方法,包括使用sendevent命令、input命令以及C/C++代码。
adbshell命令模拟按键输入input使用keycode列表详解
![adbshell命令模拟按键输入input使用keycode列表详解](https://img.taocdn.com/s3/m/43a036d2d4bbfd0a79563c1ec5da50e2524dd129.png)
adbshell命令模拟按键输⼊input使⽤keycode列表详解在adb shell⾥有⼀个⾮常使⽤的命令,模拟按键输⼊,这⾥⾸先不要理解为是键盘的模拟按键,下⾯命令的使⽤和键值做⼀个详解。
input命令格式adb shell input keyevent <keycode><keycode>对应的数值在android源码中定义如下/** Key code constant: Unknown key code. */public static final int KEYCODE_UNKNOWN = 0;/** Key code constant: Soft Left key.* Usually situated below the display on phones and used as a multi-function* feature key for selecting a software defined function shown on the bottom left* of the display. */public static final int KEYCODE_SOFT_LEFT = 1;/** Key code constant: Soft Right key.* Usually situated below the display on phones and used as a multi-function* feature key for selecting a software defined function shown on the bottom right* of the display. */public static final int KEYCODE_SOFT_RIGHT = 2;/** Key code constant: Home key.* This key is handled by the framework and is never delivered to applications. */public static final int KEYCODE_HOME = 3;/** Key code constant: Back key. */public static final int KEYCODE_BACK = 4;/** Key code constant: Call key. */public static final int KEYCODE_CALL = 5;/** Key code constant: End Call key. */public static final int KEYCODE_ENDCALL = 6;/** Key code constant: '0' key. */public static final int KEYCODE_0 = 7;/** Key code constant: '1' key. */public static final int KEYCODE_1 = 8;/** Key code constant: '2' key. */public static final int KEYCODE_2 = 9;/** Key code constant: '3' key. */public static final int KEYCODE_3 = 10;/** Key code constant: '4' key. */public static final int KEYCODE_4 = 11;/** Key code constant: '5' key. */public static final int KEYCODE_5 = 12;/** Key code constant: '6' key. */public static final int KEYCODE_6 = 13;/** Key code constant: '7' key. */public static final int KEYCODE_7 = 14;/** Key code constant: '8' key. */public static final int KEYCODE_8 = 15;/** Key code constant: '9' key. */public static final int KEYCODE_9 = 16;/** Key code constant: '*' key. */public static final int KEYCODE_STAR = 17;/** Key code constant: '#' key. */public static final int KEYCODE_POUND = 18;/** Key code constant: Directional Pad Up key.* May also be synthesized from trackball motions. */public static final int KEYCODE_DPAD_UP = 19;/** Key code constant: Directional Pad Down key.* May also be synthesized from trackball motions. */public static final int KEYCODE_DPAD_DOWN = 20;/** Key code constant: Directional Pad Left key.* May also be synthesized from trackball motions. */public static final int KEYCODE_DPAD_LEFT = 21;/** Key code constant: Directional Pad Right key.* May also be synthesized from trackball motions. */public static final int KEYCODE_DPAD_RIGHT = 22;/** Key code constant: Directional Pad Center key.* May also be synthesized from trackball motions. */public static final int KEYCODE_DPAD_CENTER = 23;/** Key code constant: Volume Up key.* Adjusts the speaker volume up. */public static final int KEYCODE_VOLUME_UP = 24;/** Key code constant: Volume Down key.* Adjusts the speaker volume down. */public static final int KEYCODE_VOLUME_DOWN = 25;/** Key code constant: Power key. *//** Key code constant: Clear key. */public static final int KEYCODE_CLEAR = 28; /** Key code constant: 'A' key. */public static final int KEYCODE_A = 29;/** Key code constant: 'B' key. */public static final int KEYCODE_B = 30;/** Key code constant: 'C' key. */public static final int KEYCODE_C = 31;/** Key code constant: 'D' key. */public static final int KEYCODE_D = 32;/** Key code constant: 'E' key. */public static final int KEYCODE_E = 33;/** Key code constant: 'F' key. */public static final int KEYCODE_F = 34;/** Key code constant: 'G' key. */public static final int KEYCODE_G = 35;/** Key code constant: 'H' key. */public static final int KEYCODE_H = 36;/** Key code constant: 'I' key. */public static final int KEYCODE_I = 37;/** Key code constant: 'J' key. */public static final int KEYCODE_J = 38;/** Key code constant: 'K' key. */public static final int KEYCODE_K = 39;/** Key code constant: 'L' key. */public static final int KEYCODE_L = 40;/** Key code constant: 'M' key. */public static final int KEYCODE_M = 41;/** Key code constant: 'N' key. */public static final int KEYCODE_N = 42;/** Key code constant: 'O' key. */public static final int KEYCODE_O = 43;/** Key code constant: 'P' key. */public static final int KEYCODE_P = 44;/** Key code constant: 'Q' key. */public static final int KEYCODE_Q = 45;/** Key code constant: 'R' key. */public static final int KEYCODE_R = 46;/** Key code constant: 'S' key. */public static final int KEYCODE_S = 47;/** Key code constant: 'T' key. */public static final int KEYCODE_T = 48;/** Key code constant: 'U' key. */public static final int KEYCODE_U = 49;/** Key code constant: 'V' key. */public static final int KEYCODE_V = 50;/** Key code constant: 'W' key. */public static final int KEYCODE_W = 51;/** Key code constant: 'X' key. */public static final int KEYCODE_X = 52;/** Key code constant: 'Y' key. */public static final int KEYCODE_Y = 53;/** Key code constant: 'Z' key. */public static final int KEYCODE_Z = 54;/** Key code constant: ',' key. */public static final int KEYCODE_COMMA = 55; /** Key code constant: '.' key. */public static final int KEYCODE_PERIOD = 56; /** Key code constant: Left Alt modifier key. */public static final int KEYCODE_ALT_LEFT = 57; /** Key code constant: Right Alt modifier key. */public static final int KEYCODE_ALT_RIGHT = 58; /** Key code constant: Left Shift modifier key. */ public static final int KEYCODE_SHIFT_LEFT = 59; /** Key code constant: Right Shift modifier key. */ public static final int KEYCODE_SHIFT_RIGHT = 60; /** Key code constant: Tab key. */public static final int KEYCODE_TAB = 61;/** Key code constant: Space key. */public static final int KEYCODE_SPACE = 62; /** Key code constant: Symbol modifier key.* Used to enter alternate symbols. */public static final int KEYCODE_SYM = 63;/** Key code constant: Explorer special function key.* Used to launch a browser application. */public static final int KEYCODE_EXPLORER = 64; /** Key code constant: Envelope special function key. * Used to launch a mail application. */public static final int KEYCODE_ENVELOPE = 65; /** Key code constant: Enter key. *//** Key code constant: '`' (backtick) key. */public static final int KEYCODE_GRAVE = 68;/** Key code constant: '-'. */public static final int KEYCODE_MINUS = 69;/** Key code constant: '=' key. */public static final int KEYCODE_EQUALS = 70;/** Key code constant: '[' key. */public static final int KEYCODE_LEFT_BRACKET = 71;/** Key code constant: ']' key. */public static final int KEYCODE_RIGHT_BRACKET = 72;/** Key code constant: '\' key. */public static final int KEYCODE_BACKSLASH = 73;/** Key code constant: ';' key. */public static final int KEYCODE_SEMICOLON = 74;/** Key code constant: ''' (apostrophe) key. */public static final int KEYCODE_APOSTROPHE = 75;/** Key code constant: '/' key. */public static final int KEYCODE_SLASH = 76;/** Key code constant: '@' key. */public static final int KEYCODE_AT = 77;/** Key code constant: Number modifier key.* Used to enter numeric symbols.* This key is not Num Lock; it is more like {@link #KEYCODE_ALT_LEFT} and is* interpreted as an ALT key by {@link android.text.method.MetaKeyKeyListener}. */public static final int KEYCODE_NUM = 78;/** Key code constant: Headset Hook key.* Used to hang up calls and stop media. */public static final int KEYCODE_HEADSETHOOK = 79;/** Key code constant: Camera Focus key.* Used to focus the camera. */public static final int KEYCODE_FOCUS = 80; // *Camera* focus/** Key code constant: '+' key. */public static final int KEYCODE_PLUS = 81;/** Key code constant: Menu key. */public static final int KEYCODE_MENU = 82;/** Key code constant: Notification key. */public static final int KEYCODE_NOTIFICATION = 83;/** Key code constant: Search key. */public static final int KEYCODE_SEARCH = 84;/** Key code constant: Play/Pause media key. */public static final int KEYCODE_MEDIA_PLAY_PAUSE= 85;/** Key code constant: Stop media key. */public static final int KEYCODE_MEDIA_STOP = 86;/** Key code constant: Play Next media key. */public static final int KEYCODE_MEDIA_NEXT = 87;/** Key code constant: Play Previous media key. */public static final int KEYCODE_MEDIA_PREVIOUS = 88;/** Key code constant: Rewind media key. */public static final int KEYCODE_MEDIA_REWIND = 89;/** Key code constant: Fast Forward media key. */public static final int KEYCODE_MEDIA_FAST_FORWARD = 90;/** Key code constant: Mute key.* Mutes the microphone, unlike {@link #KEYCODE_VOLUME_MUTE}. */public static final int KEYCODE_MUTE = 91;/** Key code constant: Page Up key. */public static final int KEYCODE_PAGE_UP = 92;/** Key code constant: Page Down key. */public static final int KEYCODE_PAGE_DOWN = 93;/** Key code constant: Picture Symbols modifier key.* Used to switch symbol sets (Emoji, Kao-moji). */public static final int KEYCODE_PICTSYMBOLS = 94; // switch symbol-sets (Emoji,Kao-moji) /** Key code constant: Switch Charset modifier key.* Used to switch character sets (Kanji, Katakana). */public static final int KEYCODE_SWITCH_CHARSET = 95; // switch char-sets (Kanji,Katakana) /** Key code constant: A Button key.* On a game controller, the A button should be either the button labeled A* or the first button on the bottom row of controller buttons. */public static final int KEYCODE_BUTTON_A = 96;/** Key code constant: B Button key.* On a game controller, the B button should be either the button labeled B* or the second button on the bottom row of controller buttons. */public static final int KEYCODE_BUTTON_B = 97;/** Key code constant: C Button key.* On a game controller, the C button should be either the button labeled C* or the third button on the bottom row of controller buttons. */public static final int KEYCODE_BUTTON_C = 98;/** Key code constant: X Button key.* On a game controller, the X button should be either the button labeled X* or the first button on the upper row of controller buttons. *//** Key code constant: Z Button key.* On a game controller, the Z button should be either the button labeled Z* or the third button on the upper row of controller buttons. */public static final int KEYCODE_BUTTON_Z = 101;/** Key code constant: L1 Button key.* On a game controller, the L1 button should be either the button labeled L1 (or L)* or the top left trigger button. */public static final int KEYCODE_BUTTON_L1 = 102;/** Key code constant: R1 Button key.* On a game controller, the R1 button should be either the button labeled R1 (or R)* or the top right trigger button. */public static final int KEYCODE_BUTTON_R1 = 103;/** Key code constant: L2 Button key.* On a game controller, the L2 button should be either the button labeled L2* or the bottom left trigger button. */public static final int KEYCODE_BUTTON_L2 = 104;/** Key code constant: R2 Button key.* On a game controller, the R2 button should be either the button labeled R2* or the bottom right trigger button. */public static final int KEYCODE_BUTTON_R2 = 105;/** Key code constant: Left Thumb Button key.* On a game controller, the left thumb button indicates that the left (or only)* joystick is pressed. */public static final int KEYCODE_BUTTON_THUMBL = 106;/** Key code constant: Right Thumb Button key.* On a game controller, the right thumb button indicates that the right* joystick is pressed. */public static final int KEYCODE_BUTTON_THUMBR = 107;/** Key code constant: Start Button key.* On a game controller, the button labeled Start. */public static final int KEYCODE_BUTTON_START = 108;/** Key code constant: Select Button key.* On a game controller, the button labeled Select. */public static final int KEYCODE_BUTTON_SELECT = 109;/** Key code constant: Mode Button key.* On a game controller, the button labeled Mode. */public static final int KEYCODE_BUTTON_MODE = 110;/** Key code constant: Escape key. */public static final int KEYCODE_ESCAPE = 111;/** Key code constant: Forward Delete key.* Deletes characters ahead of the insertion point, unlike {@link #KEYCODE_DEL}. */ public static final int KEYCODE_FORWARD_DEL = 112;/** Key code constant: Left Control modifier key. */public static final int KEYCODE_CTRL_LEFT = 113;/** Key code constant: Right Control modifier key. */public static final int KEYCODE_CTRL_RIGHT = 114;/** Key code constant: Caps Lock key. */public static final int KEYCODE_CAPS_LOCK = 115;/** Key code constant: Scroll Lock key. */public static final int KEYCODE_SCROLL_LOCK = 116;/** Key code constant: Left Meta modifier key. */public static final int KEYCODE_META_LEFT = 117;/** Key code constant: Right Meta modifier key. */public static final int KEYCODE_META_RIGHT = 118;/** Key code constant: Function modifier key. */public static final int KEYCODE_FUNCTION = 119;/** Key code constant: System Request / Print Screen key. */public static final int KEYCODE_SYSRQ = 120;/** Key code constant: Break / Pause key. */public static final int KEYCODE_BREAK = 121;/** Key code constant: Home Movement key.* Used for scrolling or moving the cursor around to the start of a line* or to the top of a list. */public static final int KEYCODE_MOVE_HOME = 122;/** Key code constant: End Movement key.* Used for scrolling or moving the cursor around to the end of a line* or to the bottom of a list. */public static final int KEYCODE_MOVE_END = 123;/** Key code constant: Insert key.* Toggles insert / overwrite edit mode. */public static final int KEYCODE_INSERT = 124;/** Key code constant: Forward key.* Navigates forward in the history stack. Complement of {@link #KEYCODE_BACK}. */ public static final int KEYCODE_FORWARD = 125;/** Key code constant: Play media key. */public static final int KEYCODE_MEDIA_PLAY = 126;/** Key code constant: Pause media key. */public static final int KEYCODE_MEDIA_PAUSE = 127;/** Key code constant: Close media key./** Key code constant: Record media key. */public static final int KEYCODE_MEDIA_RECORD = 130;/** Key code constant: F1 key. */public static final int KEYCODE_F1 = 131;/** Key code constant: F2 key. */public static final int KEYCODE_F2 = 132;/** Key code constant: F3 key. */public static final int KEYCODE_F3 = 133;/** Key code constant: F4 key. */public static final int KEYCODE_F4 = 134;/** Key code constant: F5 key. */public static final int KEYCODE_F5 = 135;/** Key code constant: F6 key. */public static final int KEYCODE_F6 = 136;/** Key code constant: F7 key. */public static final int KEYCODE_F7 = 137;/** Key code constant: F8 key. */public static final int KEYCODE_F8 = 138;/** Key code constant: F9 key. */public static final int KEYCODE_F9 = 139;/** Key code constant: F10 key. */public static final int KEYCODE_F10 = 140;/** Key code constant: F11 key. */public static final int KEYCODE_F11 = 141;/** Key code constant: F12 key. */public static final int KEYCODE_F12 = 142;/** Key code constant: Num Lock key.* This is the Num Lock key; it is different from {@link #KEYCODE_NUM}.* This key alters the behavior of other keys on the numeric keypad. */public static final int KEYCODE_NUM_LOCK = 143;/** Key code constant: Numeric keypad '0' key. */public static final int KEYCODE_NUMPAD_0 = 144;/** Key code constant: Numeric keypad '1' key. */public static final int KEYCODE_NUMPAD_1 = 145;/** Key code constant: Numeric keypad '2' key. */public static final int KEYCODE_NUMPAD_2 = 146;/** Key code constant: Numeric keypad '3' key. */public static final int KEYCODE_NUMPAD_3 = 147;/** Key code constant: Numeric keypad '4' key. */public static final int KEYCODE_NUMPAD_4 = 148;/** Key code constant: Numeric keypad '5' key. */public static final int KEYCODE_NUMPAD_5 = 149;/** Key code constant: Numeric keypad '6' key. */public static final int KEYCODE_NUMPAD_6 = 150;/** Key code constant: Numeric keypad '7' key. */public static final int KEYCODE_NUMPAD_7 = 151;/** Key code constant: Numeric keypad '8' key. */public static final int KEYCODE_NUMPAD_8 = 152;/** Key code constant: Numeric keypad '9' key. */public static final int KEYCODE_NUMPAD_9 = 153;/** Key code constant: Numeric keypad '/' key (for division). */public static final int KEYCODE_NUMPAD_DIVIDE = 154;/** Key code constant: Numeric keypad '*' key (for multiplication). */public static final int KEYCODE_NUMPAD_MULTIPLY = 155;/** Key code constant: Numeric keypad '-' key (for subtraction). */public static final int KEYCODE_NUMPAD_SUBTRACT = 156;/** Key code constant: Numeric keypad '+' key (for addition). */public static final int KEYCODE_NUMPAD_ADD = 157;/** Key code constant: Numeric keypad '.' key (for decimals or digit grouping). */ public static final int KEYCODE_NUMPAD_DOT = 158;/** Key code constant: Numeric keypad ',' key (for decimals or digit grouping). */ public static final int KEYCODE_NUMPAD_COMMA = 159;/** Key code constant: Numeric keypad Enter key. */public static final int KEYCODE_NUMPAD_ENTER = 160;/** Key code constant: Numeric keypad '=' key. */public static final int KEYCODE_NUMPAD_EQUALS = 161;/** Key code constant: Numeric keypad '(' key. */public static final int KEYCODE_NUMPAD_LEFT_PAREN = 162;/** Key code constant: Numeric keypad ')' key. */public static final int KEYCODE_NUMPAD_RIGHT_PAREN = 163;/** Key code constant: Volume Mute key.* Mutes the speaker, unlike {@link #KEYCODE_MUTE}.* This key should normally be implemented as a toggle such that the first press * mutes the speaker and the second press restores the original volume. */ public static final int KEYCODE_VOLUME_MUTE = 164;/** Key code constant: Info key.* Common on TV remotes to show additional information related to what is* currently being viewed. */public static final int KEYCODE_INFO = 165;/** Key code constant: Zoom in key. */public static final int KEYCODE_ZOOM_IN = 168;/** Key code constant: Zoom out key. */public static final int KEYCODE_ZOOM_OUT = 169;/** Key code constant: TV key.* On TV remotes, switches to viewing live TV. */public static final int KEYCODE_TV = 170;/** Key code constant: Window key.* On TV remotes, toggles picture-in-picture mode or other windowing functions. */ public static final int KEYCODE_WINDOW = 171;/** Key code constant: Guide key.* On TV remotes, shows a programming guide. */public static final int KEYCODE_GUIDE = 172;/** Key code constant: DVR key.* On some TV remotes, switches to a DVR mode for recorded shows. */public static final int KEYCODE_DVR = 173;/** Key code constant: Bookmark key.* On some TV remotes, bookmarks content or web pages. */public static final int KEYCODE_BOOKMARK = 174;/** Key code constant: Toggle captions key.* Switches the mode for closed-captioning text, for example during television shows. */ public static final int KEYCODE_CAPTIONS = 175;/** Key code constant: Settings key.* Starts the system settings activity. */public static final int KEYCODE_SETTINGS = 176;/** Key code constant: TV power key.* On TV remotes, toggles the power on a television screen. */public static final int KEYCODE_TV_POWER = 177;/** Key code constant: TV input key.* On TV remotes, switches the input on a television screen. */public static final int KEYCODE_TV_INPUT = 178;/** Key code constant: Set-top-box power key.* On TV remotes, toggles the power on an external Set-top-box. */public static final int KEYCODE_STB_POWER = 179;/** Key code constant: Set-top-box input key.* On TV remotes, switches the input mode on an external Set-top-box. */public static final int KEYCODE_STB_INPUT = 180;/** Key code constant: A/V Receiver power key.* On TV remotes, toggles the power on an external A/V Receiver. */public static final int KEYCODE_AVR_POWER = 181;/** Key code constant: A/V Receiver input key.* On TV remotes, switches the input mode on an external A/V Receiver. */public static final int KEYCODE_AVR_INPUT = 182;/** Key code constant: Red "programmable" key.* On TV remotes, acts as a contextual/programmable key. */public static final int KEYCODE_PROG_RED = 183;/** Key code constant: Green "programmable" key.* On TV remotes, actsas a contextual/programmable key. */public static final int KEYCODE_PROG_GREEN = 184;/** Key code constant: Yellow "programmable" key.* On TV remotes, acts as a contextual/programmable key. */public static final int KEYCODE_PROG_YELLOW = 185;/** Key code constant: Blue "programmable" key.* On TV remotes, acts as a contextual/programmable key. */public static final int KEYCODE_PROG_BLUE = 186;/** Key code constant: App switch key.* Should bring up the application switcher dialog. */public static final int KEYCODE_APP_SWITCH = 187;/** Key code constant: Generic Game Pad Button #1.*/public static final int KEYCODE_BUTTON_1 = 188;/** Key code constant: Generic Game Pad Button #2.*/public static final int KEYCODE_BUTTON_2 = 189;/** Key code constant: Generic Game Pad Button #3.*/public static final int KEYCODE_BUTTON_3 = 190;/** Key code constant: Generic Game Pad Button #4.*/public static final int KEYCODE_BUTTON_4 = 191;/** Key code constant: Generic Game Pad Button #5.*/public static final int KEYCODE_BUTTON_5 = 192;/** Key code constant: Generic Game Pad Button #6.*/public static final int KEYCODE_BUTTON_6 = 193;/** Key code constant: Generic Game Pad Button #7.*/public static final int KEYCODE_BUTTON_7 = 194;/** Key code constant: Generic Game Pad Button #8.*/public static final int KEYCODE_BUTTON_8 = 195;/** Key code constant: Generic Game Pad Button #9.*/public static final int KEYCODE_BUTTON_9 = 196;/** Key code constant: Generic Game Pad Button #10.*/public static final int KEYCODE_BUTTON_10 = 197;/** Key code constant: Generic Game Pad Button #14.*/public static final int KEYCODE_BUTTON_14 = 201;/** Key code constant: Generic Game Pad Button #15.*/public static final int KEYCODE_BUTTON_15 = 202;/** Key code constant: Generic Game Pad Button #16.*/public static final int KEYCODE_BUTTON_16 = 203;/** Key code constant: Language Switch key.* Toggles the current input language such as switching between English and Japanese on * a QWERTY keyboard. On some devices, the same function may be performed by* pressing Shift+Spacebar. */public static final int KEYCODE_LANGUAGE_SWITCH = 204;/** Key code constant: Manner Mode key.* Toggles silent or vibrate mode on and off to make the device behave more politely* in certain settings such as on a crowded train. On some devices, the key may only* operate when long-pressed. */public static final int KEYCODE_MANNER_MODE = 205;/** Key code constant: 3D Mode key.* Toggles the display between 2D and 3D mode. */public static final int KEYCODE_3D_MODE = 206;/** Key code constant: Contacts special function key.* Used to launch an address book application. */public static final int KEYCODE_CONTACTS = 207;/** Key code constant: Calendar special function key.* Used to launch a calendar application. */public static final int KEYCODE_CALENDAR = 208;/** Key code constant: Music special function key.* Used to launch a music player application. */public static final int KEYCODE_MUSIC = 209;/** Key code constant: Calculator special function key.* Used to launch a calculator application. */public static final int KEYCODE_CALCULATOR = 210;/** Key code constant: Japanese full-width / half-width key. */public static final int KEYCODE_ZENKAKU_HANKAKU = 211;/** Key code constant: Japanese alphanumeric key. */public static final int KEYCODE_EISU = 212;/** Key code constant: Japanese non-conversion key. */public static final int KEYCODE_MUHENKAN = 213;/** Key code constant: Japanese conversion key. */public static final int KEYCODE_HENKAN = 214;/** Key code constant: Japanese katakana / hiragana key. */public static final int KEYCODE_KATAKANA_HIRAGANA = 215;/** Key code constant: Japanese Yen key. */public static final int KEYCODE_YEN = 216;/** Key code constant: Japanese Ro key. */public static final int KEYCODE_RO = 217;/** Key code constant: Japanese kana key. */public static final int KEYCODE_KANA = 218;/** Key code constant: Assist key.* Launches the global assist activity. Not delivered to applications. */public static final int KEYCODE_ASSIST = 219;/** Key code constant: Brightness Down key.* Adjusts the screen brightness down. */public static final int KEYCODE_BRIGHTNESS_DOWN = 220;/** Key code constant: Brightness Up key.* Adjusts the screen brightness up. */public static final int KEYCODE_BRIGHTNESS_UP = 221;/** Key code constant: Audio Track key.* Switches the audio tracks. */public static final int KEYCODE_MEDIA_AUDIO_TRACK = 222;/** Key code constant: Sleep key.* Puts the device to sleep. Behaves somewhat like {@link #KEYCODE_POWER} but it * has no effect if the device is already asleep. */public static final int KEYCODE_SLEEP = 223;/** Key code constant: Wakeup key.* Wakes up the device. Behaves somewhat like {@link #KEYCODE_POWER} but it* has no effect if the device is already awake. */public static final int KEYCODE_WAKEUP = 224;/** Key code constant: Pairing key.* Initiates peripheral pairing mode. Useful for pairing remote control* devices or game controllers, especially if no other input mode is* available. */public static final int KEYCODE_PAIRING = 225;/** Key code constant: Media Top Menu key.* Goes to the top of media menu. */public static final int KEYCODE_MEDIA_TOP_MENU = 226;/** Key code constant: '11' key. */public static final int KEYCODE_11 = 227;/** Key code constant: '12' key. */* Displays data services like weather, sports. */public static final int KEYCODE_TV_DATA_SERVICE = 230;/** Key code constant: Voice Assist key.* Launches the global voice assist activity. Not delivered to applications. */public static final int KEYCODE_VOICE_ASSIST = 231;/** Key code constant: Radio key.* Toggles TV service / Radio service. */public static final int KEYCODE_TV_RADIO_SERVICE = 232;/** Key code constant: Teletext key.* Displays Teletext service. */public static final int KEYCODE_TV_TELETEXT = 233;/** Key code constant: Number entry key.* Initiates to enter multi-digit channel nubmber when each digit key is assigned* for selecting separate channel. Corresponds to Number Entry Mode (0x1D) of CEC * User Control Code. */public static final int KEYCODE_TV_NUMBER_ENTRY = 234;/** Key code constant: Analog Terrestrial key.* Switches to analog terrestrial broadcast service. */public static final int KEYCODE_TV_TERRESTRIAL_ANALOG = 235;/** Key code constant: Digital Terrestrial key.* Switches to digital terrestrial broadcast service. */public static final int KEYCODE_TV_TERRESTRIAL_DIGITAL = 236;/** Key code constant: Satellite key.* Switches to digital satellite broadcast service. */public static final int KEYCODE_TV_SATELLITE = 237;/** Key code constant: BS key.* Switches to BS digital satellite broadcasting service available in Japan. */public static final int KEYCODE_TV_SATELLITE_BS = 238;/** Key code constant: CS key.* Switches to CS digital satellite broadcasting service available in Japan. */public static final int KEYCODE_TV_SATELLITE_CS = 239;/** Key code constant: BS/CS key.* Toggles between BS and CS digital satellite services. */public static final int KEYCODE_TV_SATELLITE_SERVICE = 240;/** Key code constant: Toggle Network key.* Toggles selecting broacast services. */public static final int KEYCODE_TV_NETWORK = 241;/** Key code constant: Antenna/Cable key.* Toggles broadcast input source between antenna and cable. */public static final int KEYCODE_TV_ANTENNA_CABLE = 242;/** Key code constant: HDMI #1 key.* Switches to HDMI input #1. */public static final int KEYCODE_TV_INPUT_HDMI_1 = 243;/** Key code constant: HDMI #2 key.* Switches to HDMI input #2. */public static final int KEYCODE_TV_INPUT_HDMI_2 = 244;/** Key code constant: HDMI #3 key.* Switches to HDMI input #3. */public static final int KEYCODE_TV_INPUT_HDMI_3 = 245;/** Key code constant: HDMI #4 key.* Switches to HDMI input #4. */public static final int KEYCODE_TV_INPUT_HDMI_4 = 246;/** Key code constant: Composite #1 key.* Switches to composite video input #1. */public static final int KEYCODE_TV_INPUT_COMPOSITE_1 = 247;/** Key code constant: Composite #2 key.* Switches to composite video input #2. */public static final int KEYCODE_TV_INPUT_COMPOSITE_2 = 248;/** Key code constant: Component #1 key.* Switches to component video input #1. */public static final int KEYCODE_TV_INPUT_COMPONENT_1 = 249;/** Key code constant: Component #2 key.* Switches to component video input #2. */public static final int KEYCODE_TV_INPUT_COMPONENT_2 = 250;/** Key code constant: VGA #1 key.* Switches to VGA (analog RGB) input #1. */public static final int KEYCODE_TV_INPUT_VGA_1 = 251;/** Key code constant: Audio description key.* Toggles audio description off / on. */public static final int KEYCODE_TV_AUDIO_DESCRIPTION = 252;/** Key code constant: Audio description mixing volume up key.* Louden audio description volume as compared with normal audio volume. */ public static final int KEYCODE_TV_AUDIO_DESCRIPTION_MIX_UP = 253;/** Key code constant: Audio description mixing volume down key.* Lessen audio description volume as compared with normal audio volume. */ public static final int KEYCODE_TV_AUDIO_DESCRIPTION_MIX_DOWN = 254;/** Key code constant: Zoom mode key.* Changes Zoom mode (Normal, Full, Zoom, Wide-zoom, etc.) */public static final int KEYCODE_TV_ZOOM_MODE = 255;。
adb使用技巧
![adb使用技巧](https://img.taocdn.com/s3/m/cde82fa8f9c75fbfc77da26925c52cc58ad6906a.png)
ADB(Android Debug Bridge)是一个强大的命令行工具,它允许您与设备进行通信。
以下是使用ADB的一些技巧:1. 安装和卸载应用程序:您可以使用ADB安装和卸载应用程序。
只需在命令行中输入“adb install <应用程序路径>”即可安装应用程序,输入“adb uninstall <包名>”即可卸载应用程序。
2. 重启设备和模拟器:您可以使用ADB命令重新启动设备和模拟器。
只需输入“adb reboot”即可重新启动设备或模拟器。
3. 获取设备列表:您可以使用ADB命令列出连接的设备。
只需输入“adb devices”即可获取设备列表。
4. 安装和卸载驱动程序:如果您需要在Windows上使用ADB,则需要安装Android SDK Platform-Tools,它包含ADB驱动程序。
要卸载驱动程序,请在设备管理器中卸载与ADB相关的设备,然后重新启动计算机。
5. 导出和导入文件:您可以使用ADB命令将文件从计算机导入到设备或从设备导出到计算机。
只需输入“adb pull <源文件路径>”即可将文件从设备导出到计算机,输入“adb push <目标文件路径>”即可将文件从计算机导入到设备。
6. 模拟按键和鼠标事件:您可以使用ADB命令模拟按键和鼠标事件,例如按下和释放键、单击和双击鼠标等。
只需输入“adb shell input keyevent <键值>”或“adb shell input tap <坐标>”即可模拟按键或鼠标事件。
7. 查看和修改日志:您可以使用ADB命令查看和修改Android设备的日志。
只需输入“adb logcat”即可查看日志,输入“adb shell log write <消息>”即可向日志中写入消息。
这些是使用ADB的一些技巧,但ADB还有许多其他功能等待您去探索。
Android手机上,利用bat脚本模拟用户操作
![Android手机上,利用bat脚本模拟用户操作](https://img.taocdn.com/s3/m/e0688e35cdbff121dd36a32d7375a417866fc1b1.png)
Android⼿机上,利⽤bat脚本模拟⽤户操作利⽤bat脚本模拟⽤户操作,需要⽤到两点:①就是adb命令了,adb命令可以⽤来模拟⽤户在⼿机上的操作②bat语⾔,就是批处理语⾔,主要⽤来进⾏逻辑处理,跟众多语⾔语法⼀样,批处理语⾔也包括for循环、if语句之类的语法;⼀、adb命令⾸先我们来介绍模拟⽤户在⼿机上操作的adb命令input keyevent //发送键盘事件⽤法说明:adb shell input keyevent “value”usage: input ...input text <string> //在EditText中输⼊字符串input keyevent <key code number or name> //模拟back键、home键、⾳量键等操作input tap <x> <y> //模拟点击事件input swipe <x1> <y1> <x2> <y2> //模拟滑动事件看看上⾯的这四个命令是不是已经满⾜你⽇常使⽤了呢?先列举input keyevent⼏个⽐较常⽤的code值:input keyevent 3 // Homeinput keyevent 4 // Backinput keyevent 19 //Upinput keyevent 20 //Downinput keyevent 21 //Leftinput keyevent 22 //Rightinput keyevent 23 //Select/Okinput keyevent 24 //Volume+input keyevent 25 // Volume-input keyevent 82 // Menu 菜单~~~下⾯来举个栗⼦:①你可以先进⼊到adb shell中,再执⾏input keyevent "value",如下,看看是不是执⾏了home键的操作呢:shell@android:/ $ input keyevent 3②你也可以不进⼊adb shell中,直接执⾏(在bat脚本中写的时候当然要⽤这种啦~),如下:adb shell input tap 1431850 //这是点击了横坐标为143、纵坐标为1850的像素点adb shell input swipe 200100444666 //这是从坐标点(200,100)滑动到了坐标(444,666)========================================【快速获取想要点击图标像素点的技巧:】想要点击某个button,但是怎么快速获取该button的像素位置呢?⼀般Android在[设置--⾼级设置--开发者选项]中,或者[设置--开发⼈员选项]中,有“指针位置”这⼀项,打开该开关不要怀疑⽔印,我是从⾃⼰博客拿过来的:)如上图,⽅框的位置就是你所点击的区域坐标点,注意,原坐标[0, 0]就是⼿机屏幕的左上⾓。
[全]adb shell命令测试手机和模拟器的必会技术
![[全]adb shell命令测试手机和模拟器的必会技术](https://img.taocdn.com/s3/m/0d2954abb84ae45c3a358c06.png)
adb shell命令测试手机和模拟器的必会技术* 查看设备adb devicesps这个命令是查看当前连接的设备, 连接到计算机的android设备或者模拟器将会列出显示若有多台安卓设备,可以通过在adb后面加上-s <设备id> 对指定设备进行装包、卸载等操作*启动adbadb start-server*关闭adbadb kill-server* 安装软件adb install <apk文件路径>* 卸载软件adb uninstall <应用进程名>*卸载app但保留数据和缓存文件adb uninstall -k<package>*重新启动识别adb reboot*重启到bootloader,即刷机模式adb reboot bootloader*重启到recovery,即恢复模式adb reboot recovery*从电脑上发送文件到设备adb push <本地路径> <远程路径>ps: 用push命令可以把本机电脑上的文件或者文件夹复制到设备(手机)*从设备上下载文件到电脑adb pull <远程路径> <本地路径>ps: 用pull命令可以把设备(手机)上的文件或者文件夹复制到本机电脑*取得设备root权限adb remount*登录设备shelladb shelladb shell<command命令>ps: adb shell 后面加的是linux系统操作指令,也即直接运行设备命令, 相当于执行远程命令-查看手机产线版本adb shellcat/sys/devices/mx_tsp/appid-查看手机运营商版本adb shellcat/proc/lk_info/sw_version-查看手机是否加密adb shellcat/proc/lk_info/sec(返回0则非加密。
模拟键盘鼠标事件
![模拟键盘鼠标事件](https://img.taocdn.com/s3/m/38e142d7d5bbfd0a79567339.png)
android中的MotionEvent 及其它事件处理2014-09-18 08:47 7386人阅读评论(0) 收藏举报MotionEvent对象当用户触摸屏幕时将创建一个MotionEvent对象。
MotionEvent包含关于发生触摸的位置和时间等细节信息。
MotionEvent对象被传递到程序中合适的方法比如View对象的onTouchEvent()方法中。
在这些方法中我们可以分析MotionEvent对象那个,以决定要执行的操作。
MotionEvent对象是与用户触摸相关的时间序列,该序列从用户首次触摸屏幕开始,经历手指在屏幕表面的任何移动,直到手指离开屏幕时结束。
手指的初次触摸(ACTION_DOWN 操作),滑动(ACTION_MOVE操作)和抬起(ACTION_UP)都会创建MotionEvent对象。
所以每次触摸时候这三个操作是肯定发生的,而在移动过程中会产生大量事件,每个事件都会产生对应的MotionEvent对象记录发生的操作,触摸的位置,使用的多大压力,触摸的面积,合适发生,以及最初的ACTION_DOWN和时发生等相关的信息。
在设置事件时我们有2种设置的方式,一种是委托式一种是回调式。
第一种就是将事件的处理委托给监听器处理,你可以定义一个View.OnTouchListener接口的子类作为监听器,其中有onTouch()方法。
而第二种是重写View类自己本身的onTouchEvent方法,也就是控件自己处理事件。
onTouch方法接收一个MotionEvent参数和一个View参数,而onTouchEvent方法仅接收MotionEvent参数。
这是因为监听器可以监听多个View 控件的事件。
通过MotionEvent方法getation可以得到该Motionevent具体是哪个操作如ACTION_DOWN。
1、MotionEvent中getAction()与getActionMasked()的区别如果我们在监听Ontouch()里面测试的时候会发现,这两个返回值竟然是一样的。
adb 命令模拟按键事件
![adb 命令模拟按键事件](https://img.taocdn.com/s3/m/49971c21376baf1ffc4fad70.png)
adb 命令模拟按键事件usage: input ...input textinput keyeventinput tapinput swipe1. tap他模拟的是touch屏幕的事件,只需给出x、y坐标即可。
此x、y坐标对应的是真实的屏幕分辨率,所以要根据具体手机具体看,比如你想点击屏幕(x, y) = (250, 250)位置:adb shell input tap 250 2502. swipe模拟滑动的事件,给出起点和终点的坐标即可。
滑动用500毫秒从屏幕(250, 250), 到屏幕(300, 300)即adb shell input swipe 250 250 300 300 500长按250 250 500毫秒adb shell input swipe 250 250250 250 5003. keyevent指的是android对应的keycode,比如home键的keycode=3,back键的keycode=4.然后使用的话比较简单,比如想模拟home按键:adb shell input keyevent 3请查阅下述文章,根据具体keycode编辑即可。
adb shell input keyevent 4 #这条命令相当于按了设备的Backkey键adb shell input keyevent 82 #可以解锁屏幕每个数字与keycode对应表如下:0 --> "KEYCODE_UNKNOWN"1 --> "KEYCODE_MENU"2 --> "KEYCODE_SOFT_RIGHT"3 --> "KEYCODE_HOME"4 --> "KEYCODE_BACK"5 --> "KEYCODE_CALL"6 --> "KEYCODE_ENDCALL"7 --> "KEYCODE_0"8 --> "KEYCODE_1"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"21 --> "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"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"KEYCODE列表电话键KEYCODE_CALL 拨号键 5 KEYCODE_ENDCALL 挂机键 6 KEYCODE_HOME 按键Home 3 KEYCODE_MENU 菜单键82 KEYCODE_BACK 返回键 4KEYCODE_S EA RCH 搜索键84 KEYCODE_CAMERA 拍照键27 KEYCODE_FOCUS 拍照对焦键80 KEYCODE_POWER 电源键26 KEYCODE_NOTIFICATION 通知键83 KEYCODE_MUTE 话筒静音键91 KEYCODE_VOLUME_MUTE 扬声器静音键164 KEYCODE_VOLUME_UP 音量增加键2425 KEYCODE_VOLUME_DOWN 音量减小键KEYCODE_NUM 按键Number modifierKEYCODE_INFO 按键InfoKEYCODE_APP_SW IT CH 按键App switchKEYCODE_BOOKMARK 按键BookmarkKEYCODE_AVR_INPUT 按键A/V Receiver inputKEYCODE_AVR_POWER 按键A/V Receiver powerKEYCODE_CAPTIONS 按键Toggle captionsKEYCODE_CHANNEL_DOWN 按键Channel downKEYCODE_CHANNEL_UP 按键Channel upKEYCODE_CLEAR 按键ClearKEYCODE_DVR 按键DVRKEYCODE_ENVELOPE 按键Envelope special functionKEYCODE_E XP LORER 按键Explorer special functionKEYCODE_FORWARD 按键ForwardKEYCODE_FORWARD_DEL 按键Forward DeleteKEYCODE_FUNCTION 按键Function modifierKEYCODE_G UI DE 按键GuideKEYCODE_HEADSETHOOK 按键Headset HookKEYCODE_META_LEFT 按键Left Meta modifierKEYCODE_META_RIGHT 按键Right Meta modifierKEYCODE_PICTSYMBOLS 按键Picture Symbols modifierKEYCODE_PROG_BL UE按键Blue “programmable”KEYCODE_PROG_GREEN 按键Green “programmable”KEYCODE_PROG_RED 按键Red “programmable”KEYCODE_PROG_YELLOW 按键Yellow “programmable”KEYCODE_SETTINGS 按键SettingsKEYCODE_SOFT_LEFT 按键Soft LeftKEYCODE_SOFT_RIGHT 按键Soft RightKEYCODE_STB_INPUT 按键Set-top-box inputKEYCODE_STB_POWER 按键Set-top-box powerKEYCODE_SWITCH_CHARSET 按键Switch Charset modifier KEYCODE_SYM 按键Symbol modifierKEYCODE_SYSRQ 按键System Request / Print Screen KEYCODE_TV 按键TVKEYCODE_TV_INPUT 按键TV inputKEYCODE_TV_POWER 按键TV powerKEYCODE_WINDOW 按键WindowKEYCODE_UNKNOWN 未知按键控制键KEYCODE_ENTER 回车键66 KEYCODE_ESCAPE ESC键111 KEYCODE_DPAD_CENTER 导航键确定键23 KEYCODE_DPAD_UP 导航键向上19 KEYCODE_DPAD_DOWN 导航键向下20 KEYCODE_DPAD_LEFT 导航键向左21 KEYCODE_DPAD_RIGHT 导航键向右22 KEYCODE_MOVE_HOME 光标移动到开始键122 KEYCODE_MOVE_END 光标移动到末尾键123 KEYCODE_PAGE_UP 向上翻页键92 KEYCODE_PAGE_DOWN 向下翻页键93 KEYCODE_DEL 退格键67 KEYCODE_FORWARD_DEL 删除键112 KEYCODE_IN SERT 插入键124 KEYCODE_TAB Tab键61 KEYCODE_NUM_LOCK 小键盘锁143 KEYCODE_CAPS_LOCK 大写锁定键115 KEYCODE_BREAK Break/Pause键121 KEYCODE_SCROLL_LOCK 滚动锁定键116 KEYCODE_ZOOM_IN 放大键168 KEYCODE_ZOOM_OUT 缩小键169组合键KEYCODE_ALT_LEFT Alt+Left KEYCODE_ALT_RIGHT Alt+Right KEYCODE_CTRL_LEFT Control+Left KEYCODE_CTRL_RIGHT Control+Right KEYCODE_SHIFT_LEFT Shift+LeftKEYCODE_SHIFT_RIGHT Shift+Right基本KEYCODE_0 按键'0' 7 KEYCODE_1 按键'1' 8 KEYCODE_2 按键'2' 9 KEYCODE_3 按键'3' 10 KEYCODE_4 按键'4' 11 KEYCODE_5 按键'5' 12 KEYCODE_6 按键'6' 13 KEYCODE_7 按键'7' 14 KEYCODE_8 按键'8' 15 KEYCODE_9 按键'9' 16 KEYCODE_A 按键'A' 29 KEYCODE_B 按键'B' 30 KEYCODE_C 按键'C' 31 KEYCODE_D 按键'D' 32 KEYCODE_E 按键'E' 33 KEYCODE_F 按键'F' 34 KEYCODE_G 按键'G' 35 KEYCODE_H 按键'H' 36 KEYCODE_I 按键'I' 37 KEYCODE_J 按键'J' 38 KEYCODE_K 按键'K' 39 KEYCODE_L 按键'L' 40 KEYCODE_M 按键'M' 41 KEYCODE_N 按键'N' 42 KEYCODE_O 按键'O' 43 KEYCODE_P 按键'P' 44 KEYCODE_Q 按键'Q' 45 KEYCODE_R 按键'R' 46 KEYCODE_S 按键'S' 47 KEYCODE_T 按键'T' 48 KEYCODE_U 按键'U' 49 KEYCODE_V 按键'V' 50 KEYCODE_W 按键'W' 51 KEYCODE_X 按键'X' 52 KEYCODE_Y 按键'Y' 53 KEYCODE_Z 按键'Z' 54符号KEYCODE_PLUS 按键'+'KEYCODE_MINUS 按键'-'KEYCODE_STAR 按键'*'KEYCODE_SLASH 按键'/'KEYCODE_EQUALS 按键'='KEYCODE_AT 按键'@' KEYCODE_POUND 按键'#'KEYCODE_AP OS TROPHE 按键''' (单引号) KEYCODE_BACKSLASH 按键'\'KEYCODE_COMMA 按键','KEYCODE_PERIOD 按键'.'KEYCODE_LEFT_BRACKET 按键'['KEYCODE_RIGHT_BRACKET 按键']'KEYCODE_SEM ICOLON 按键';'KEYCODE_GRAVE 按键'`'KEYCODE_SPACE 空格键小键盘KEYCODE_NUMPAD_0 小键盘按键'0' KEYCODE_NUMPAD_1 小键盘按键'1' KEYCODE_NUMPAD_2 小键盘按键'2' KEYCODE_NUMPAD_3 小键盘按键'3' KEYCODE_NUMPAD_4 小键盘按键'4' KEYCODE_NUMPAD_5 小键盘按键'5' KEYCODE_NUMPAD_6 小键盘按键'6' KEYCODE_NUMPAD_7 小键盘按键'7' KEYCODE_NUMPAD_8 小键盘按键'8' KEYCODE_NUMPAD_9 小键盘按键'9' KEYCODE_NUMPAD_ADD 小键盘按键'+' KEYCODE_NUMPAD_SUBTRACT 小键盘按键'-' KEYCODE_NUMPAD_MULT IP LY 小键盘按键'*' KEYCODE_NUMPAD_DIV IDE小键盘按键'/' KEYCODE_NUMPAD_EQUALS 小键盘按键'=' KEYCODE_NUMPAD_COMMA 小键盘按键',' KEYCODE_NUMPAD_DOT 小键盘按键'.' KEYCODE_NUMPAD_LEFT_PAREN 小键盘按键'(' KEYCODE_NUMPAD_RIGHT_PAREN 小键盘按键')' KEYCODE_NUMPAD_ENTER 小键盘按键回车功能键KEYCODE_F1 按键F1KEYCODE_F2 按键F2KEYCODE_F3 按键F3KEYCODE_F4 按键F4KEYCODE_F5 按键F5KEYCODE_F6 按键F6KEYCODE_F7 按键F7KEYCODE_F8 按键F8KEYCODE_F9 按键F9KEYCODE_F10 按键F10 KEYCODE_F11 按键F11 KEYCODE_F12 按键F12多媒体键KEYCODE_MED IA_PLAY 多媒体键播放KEYCODE_MEDIA_STOP 多媒体键停止KEYCODE_MEDIA_PAUSE 多媒体键暂停KEYCODE_MEDIA_PLAY_PAUSE 多媒体键播放/暂停KEYCODE_MEDIA_FAST_FORWARD 多媒体键快进KEYCODE_MEDIA_REWIND 多媒体键快退KEYCODE_MEDIA_NEXT 多媒体键下一首KEYCODE_MEDIA_PR EVIOUS 多媒体键上一首KEYCODE_MEDIA_CLOSE 多媒体键关闭KEYCODE_MEDIA_EJECT 多媒体键弹出KEYCODE_MEDIA_RECORD 多媒体键录音手柄按键KEYCODE_BUTTON_1 通用游戏手柄按钮#1 KEYCODE_BUTTON_2 通用游戏手柄按钮#2 KEYCODE_BUTTON_3 通用游戏手柄按钮#3 KEYCODE_BUTTON_4 通用游戏手柄按钮#4 KEYCODE_BUTTON_5 通用游戏手柄按钮#5 KEYCODE_BUTTON_6 通用游戏手柄按钮#6 KEYCODE_BUTTON_7 通用游戏手柄按钮#7 KEYCODE_BUTTON_8 通用游戏手柄按钮#8 KEYCODE_BUTTON_9 通用游戏手柄按钮#9KEYCODE_BUTTON_10 通用游戏手柄按钮#10 KEYCODE_BUTTON_11 通用游戏手柄按钮#11 KEYCODE_BUTTON_12 通用游戏手柄按钮#12 KEYCODE_BUTTON_13 通用游戏手柄按钮#13 KEYCODE_BUTTON_14 通用游戏手柄按钮#14 KEYCODE_BUTTON_15 通用游戏手柄按钮#15 KEYCODE_BUTTON_16 通用游戏手柄按钮#16 KEYCODE_BUTTON_A 游戏手柄按钮A KEYCODE_BUTTON_B 游戏手柄按钮B KEYCODE_BUTTON_C 游戏手柄按钮C KEYCODE_BUTTON_X 游戏手柄按钮X KEYCODE_BUTTON_Y 游戏手柄按钮Y KEYCODE_BUTTON_Z 游戏手柄按钮Z KEYCODE_BUTTON_L1 游戏手柄按钮L1 KEYCODE_BUTTON_L2 游戏手柄按钮L2 KEYCODE_BUTTON_R1 游戏手柄按钮R1 KEYCODE_BUTTON_R2 游戏手柄按钮R2 KEYCODE_BUTTON_MODE 游戏手柄按钮Mode KEYCODE_BUTTON_SELECT 游戏手柄按钮Select KEYCODE_BUTTON_START 游戏手柄按钮Start KEYCODE_BUTTON_THUMBL Left Thumb Button KEYCODE_BUTTON_THUMBR Right Thumb Button。
Android代码模拟物理、屏幕点击事件、APP内部自动点击...
![Android代码模拟物理、屏幕点击事件、APP内部自动点击...](https://img.taocdn.com/s3/m/f01968e277eeaeaad1f34693daef5ef7bb0d1244.png)
Android代码模拟物理、屏幕点击事件、APP内部自动点击...一、应用中模拟物理和屏幕点击事件例如,模拟对某个view的点击事件1.private void simulateClick(View view, float x, float y) {2.long downTime = SystemClock.uptimeMillis();3.final MotionEvent downEvent = MotionEvent.obtain(downTime,downTime,MotionEvent.ACTION_DOWN, x, y, 0);4.downTime += 1000;5.final MotionEvent upEvent = MotionEvent.obtain(downTime,downTime,MotionEvent.ACTION_UP, x, y, 0);6.view.onTouchEvent(downEvent);7.view.onTouchEvent(upEvent);8.downEvent.recycle();9.upEvent.recycle();10.}11.12.public void setMouseClick(int x, int y){13.MotionEvent evenDownt = MotionEvent.obtain(System.currentTimeMillis(),14.System.currentTimeMillis() + 100, MotionEvent.ACTION_DOWN, x, y, 0);15.dispatchTouchEvent(evenDownt);16.MotionEvent eventUp = MotionEvent.obtain(System.currentTimeMillis(),17.System.currentTimeMillis() + 100, MotionEvent.ACTION_UP, x, y, 0);18.dispatchTouchEvent(eventUp);19.evenDownt.recycle();20.eventUp.recycle();21.}这实现原理就是模拟两个MotionEvent (按下和提起)然后用一个View 来处理这个Event 。
adb命令模拟按键事件模拟点击事件
![adb命令模拟按键事件模拟点击事件](https://img.taocdn.com/s3/m/18b8bfd04128915f804d2b160b4e767f5acf80c4.png)
adb命令模拟按键事件模拟点击事件有时我们需要程序模拟按钮或点击,⽽⼿机本⾝⼜没有,哪么可以采取adb 模拟实现,最后再去实际设备去测试(前期⼀般都拿不到设备);如模拟上⼀⾸,下⼀⾸,暂停等,⼿机上是没有的,但有些设备上是有的;//这条命令相当于按了设备的语⾳键(按此键后,进⼊语⾳识别)public static final int KEY_VOICE = 130;adb shell input keyevent 130在Activity 中实现 onKeyDown,收到KeyEvent.KEYCODE_MEDIA_RECORD后,实现⾃⼰需要的功能,返回true即可;@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event) {if(event.getKeyCode() == KeyEvent.KEYCODE_MEDIA_RECORD){L.e("Receive KeyEvent.KEYCODE_MEDIA_RECORD");return true;}return super.onKeyDown(keyCode, event);}其它://可以解锁屏幕adb shell input keyevent 82//在屏幕上做划屏操作,前四个数为坐标点,后⾯是滑动的时间(单位毫秒)adb shell input swipe 50 250 250 250 500//在屏幕上点击坐标点x=50 y=250的位置。
adb shell input tap 50 250//输⼊字符abcadb shell input text abc附其它按键值:每个数字与keycode对应表如下:0 --> "KEYCODE_UNKNOWN"1 --> "KEYCODE_MENU"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"21 --> "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"KEYCODE列表电话键KEYCODE_CALL拨号键5 KEYCODE_ENDCALL挂机键6 KEYCODE_HOME按键Home3 KEYCODE_MENU键82 KEYCODE_BACK返回键4 KEYCODE_SRCH键84 KEYCODE_CAMERA拍照键27 KEYCODE_FOCUS拍照对焦键80 KEYCODE_POWER电源键26 KEYCODE_NOTIFICATION通知键83 KEYCODE_MUTE话筒静⾳键91 KEYCODE_VOLUME_MUTE扬声器静⾳键164 KEYCODE_VOLUME_UP⾳量增加键24 KEYCODE_VOLUME_DOWN⾳量减⼩键25控制键KEYCODE_ENTER回车键66KEYCODE_ESCAPE ESC键111 KEYCODE_DPAD_CENTER键确定键23 KEYCODE_DPAD_UP导航键向上19 KEYCODE_DPAD_DOWN导航键向下20 KEYCODE_DPAD_LEFT导航键向左21 KEYCODE_DPAD_RIGHT导航键向右22 KEYCODE_MOVE_HOME光标到开始键122 KEYCODE_MOVE_END光标移动到末尾键123 KEYCODE_PAGE_UP向上翻页键92 KEYCODE_PAGE_DOWN向下翻页键93 KEYCODE_DEL退格键67 KEYCODE_FORWARD_DEL删除键112 KEYCODE_SERT插⼊键124 KEYCODE_TAB Tab键61 KEYCODE_NUM_LOCK⼩键盘锁143 KEYCODE_CAPS_LOCK⼤写锁定键115KEYCODE_BREAK Break/Pause键121 KEYCODE_SCROLL_LOCK滚动锁定键116 KEYCODE_ZOOM_IN放⼤键168 KEYCODE_ZOOM_OUT缩⼩键169组合键KEYCODE_ALT_LEFT Alt+LeftKEYCODE_ALT_RIGHT Alt+RightKEYCODE_CTRL_LEFT Control+Left KEYCODE_CTRL_RIGHT Control+Right KEYCODE_SHIFT_LEFT Shift+LeftKEYCODE_SHIFT_RIGHT Shift+Right基本KEYCODE_0按键'0'7 KEYCODE_1按键'1'8 KEYCODE_2按键'2'9 KEYCODE_3按键'3'10 KEYCODE_4按键'4'11 KEYCODE_5按键'5'12 KEYCODE_6按键'6'13 KEYCODE_7按键'7'14 KEYCODE_8按键'8'15 KEYCODE_9按键'9'16 KEYCODE_A按键'A'29 KEYCODE_B按键'B'30 KEYCODE_C按键'C'31 KEYCODE_D按键'D'32 KEYCODE_E按键'E'33 KEYCODE_F按键'F'34 KEYCODE_G按键'G'35 KEYCODE_H按键'H'36 KEYCODE_I按键'I'37 KEYCODE_J按键'J'38 KEYCODE_K按键'K'39 KEYCODE_L按键'L'40 KEYCODE_M按键'M'41 KEYCODE_N按键'N'42 KEYCODE_O按键'O'43 KEYCODE_P按键'P'44 KEYCODE_Q按键'Q'45 KEYCODE_R按键'R'46 KEYCODE_S按键'S'47 KEYCODE_T按键'T'48 KEYCODE_U按键'U'49 KEYCODE_V按键'V'50 KEYCODE_W按键'W'51 KEYCODE_X按键'X'52 KEYCODE_Y按键'Y'53 KEYCODE_Z按键'Z'54符号KEYCODE_PLUS按键'+'KEYCODE_MINUS按键'-'KEYCODE_STAR按键'*'KEYCODE_SLASH'/' KEYCODE_EQUALS按键'=' KEYCODE_AT按键'@' KEYCODE_POUND按键'#' KEYCODE_APTROPHE按键''' (单引号) KEYCODE_BACKSLASH按键'\' KEYCODE_COMMA按键',' KEYCODE_PERIOD按键'.' KEYCODE_LEFT_BRACKET按键'[' KEYCODE_RIGHT_BRACKET按键']' KEYCODE_ICOLON按键';' KEYCODE_GRAVE按键'`' KEYCODE_SPACE空格键⼩键盘KEYCODE_NUMPAD_0⼩键盘按键'0' KEYCODE_NUMPAD_1⼩键盘按键'1' KEYCODE_NUMPAD_2⼩键盘按键'2' KEYCODE_NUMPAD_3⼩键盘按键'3' KEYCODE_NUMPAD_4⼩键盘按键'4' KEYCODE_NUMPAD_5⼩键盘按键'5' KEYCODE_NUMPAD_6⼩键盘按键'6' KEYCODE_NUMPAD_7⼩键盘按键'7' KEYCODE_NUMPAD_8⼩键盘按键'8' KEYCODE_NUMPAD_9⼩键盘按键'9' KEYCODE_NUMPAD_ADD⼩键盘按键'+' KEYCODE_NUMPAD_SUBTRACT⼩键盘按键'-' KEYCODE_NUMPAD_MULTLY⼩键盘按键'*' KEYCODE_NUMPAD_DIV⼩键盘按键'/' KEYCODE_NUMPAD_EQUALS⼩键盘按键'=' KEYCODE_NUMPAD_COMMA⼩键盘按键',' KEYCODE_NUMPAD_DOT⼩键盘按键'.' KEYCODE_NUMPAD_LEFT_PAREN⼩键盘按键'(' KEYCODE_NUMPAD_RIGHT_PAREN⼩键盘按键')' KEYCODE_NUMPAD_ENTER⼩键盘按键回车功能键KEYCODE_F1按键F1 KEYCODE_F2按键F2 KEYCODE_F3按键F3 KEYCODE_F4按键F4 KEYCODE_F5按键F5 KEYCODE_F6按键F6 KEYCODE_F7按键F7 KEYCODE_F8按键F8 KEYCODE_F9按键F9 KEYCODE_F10按键F10 KEYCODE_F11按键F11 KEYCODE_F12按键F12多媒体键KEYCODE_IA_PLAY多媒体键播放KEYCODE_MEDIA_STOP多媒体键停⽌KEYCODE_MEDIA_PAUSE多媒体键暂停KEYCODE_MEDIA_PLAY_PAUSE多媒体键播放/暂停KEYCODE_MEDIA_FAST_FORWARD多媒体键快进KEYCODE_MEDIA_REWIND多媒体键快退KEYCODE_MEDIA_NEXT多媒体键下⼀⾸KEYCODE_MEDIA_EVIOUS多媒体键上⼀⾸KEYCODE_MEDIA_CLOSE多媒体键关闭KEYCODE_MEDIA_EJECT多媒体键弹出KEYCODE_MEDIA_RECORD多媒体键录⾳⼿柄按键KEYCODE_BUTTON_1通⽤⼿柄按钮#1 KEYCODE_BUTTON_2通⽤游戏⼿柄按钮 #2 KEYCODE_BUTTON_3通⽤游戏⼿柄按钮 #3 KEYCODE_BUTTON_4通⽤游戏⼿柄按钮 #4 KEYCODE_BUTTON_5通⽤游戏⼿柄按钮 #5 KEYCODE_BUTTON_6通⽤游戏⼿柄按钮 #6 KEYCODE_BUTTON_7通⽤游戏⼿柄按钮 #7 KEYCODE_BUTTON_8通⽤游戏⼿柄按钮 #8 KEYCODE_BUTTON_9通⽤游戏⼿柄按钮 #9 KEYCODE_BUTTON_10通⽤游戏⼿柄按钮 #10 KEYCODE_BUTTON_11通⽤游戏⼿柄按钮 #11 KEYCODE_BUTTON_12通⽤游戏⼿柄按钮 #12 KEYCODE_BUTTON_13通⽤游戏⼿柄按钮 #13 KEYCODE_BUTTON_14通⽤游戏⼿柄按钮 #14 KEYCODE_BUTTON_15通⽤游戏⼿柄按钮 #15 KEYCODE_BUTTON_16通⽤游戏⼿柄按钮 #16 KEYCODE_BUTTON_A游戏⼿柄按钮 A KEYCODE_BUTTON_B游戏⼿柄按钮 B KEYCODE_BUTTON_C游戏⼿柄按钮 C KEYCODE_BUTTON_X游戏⼿柄按钮 X KEYCODE_BUTTON_Y游戏⼿柄按钮 Y KEYCODE_BUTTON_Z游戏⼿柄按钮 Z KEYCODE_BUTTON_L1游戏⼿柄按钮 L1 KEYCODE_BUTTON_L2游戏⼿柄按钮 L2 KEYCODE_BUTTON_R1游戏⼿柄按钮 R1 KEYCODE_BUTTON_R2游戏⼿柄按钮 R2 KEYCODE_BUTTON_MODE游戏⼿柄按钮 Mode KEYCODE_BUTTON_SELECT游戏⼿柄按钮 Select KEYCODE_BUTTON_START游戏⼿柄按钮 Start KEYCODE_BUTTON_THUMBL Left Thumb Button KEYCODE_BUTTON_THUMBR Right Thumb Button待查KEYCODE_NUM按键Number modifier KEYCODE_INFO按键InfoKEYCODE__SWCH按键App switchKEYCODE_BOOKMARK按键BookmarkKEYCODE_AVR_INPUT按键A/V Receiver input KEYCODE_AVR_POWER按键A/V Receiver power KEYCODE_CAPTIONS按键Toggle captions KEYCODE_CHANNEL_DOWN按键Channel downKEYCODE_CHANNEL_UP按键Channel upKEYCODE_CLEAR按键ClearKEYCODE_DVR按键DVRKEYCODE_ENVELOPE按键Envelope special function KEYCODE_ELORER按键Explorer special functionKEYCODE_ELORER按键Explorer special function KEYCODE_FORWARD按键ForwardKEYCODE_FORWARD_DEL按键Forward DeleteKEYCODE_FUNCTION按键Function modifier KEYCODE_GDE按键GuideKEYCODE_HEADSETHOOK按键Headset HookKEYCODE_META_LEFT按键Left Meta modifier KEYCODE_META_RIGHT按键Right Meta modifier KEYCODE_PICTSYMBOLS按键Picture Symbols modifier KEYCODE_PROG_BL按键Blue “programmable”KEYCODE_PROG_GREEN按键Green “programmable”KEYCODE_PROG_RED按键Red “programmable”KEYCODE_PROG_YELLOW按键Yellow “programmable”KEYCODE_SETTINGS按键SettingsKEYCODE_SOFT_LEFT按键Soft LeftKEYCODE_SOFT_RIGHT按键Soft RightKEYCODE_STB_INPUT按键Set-top-box input KEYCODE_STB_POWER按键Set-top-box power KEYCODE_SWITCH_CHARSET按键Switch Charset modifier KEYCODE_SYM按键Symbol modifier KEYCODE_SYSRQ按键System Request / Print Screen KEYCODE_TV按键TVKEYCODE_TV_INPUT按键TV inputKEYCODE_TV_POWER按键TV powerKEYCODE_WINDOW按键WindowKEYCODE_UNKNOWN未知按键。
adb shell中模拟键盘鼠标事件
![adb shell中模拟键盘鼠标事件](https://img.taocdn.com/s3/m/062e411452d380eb62946d4f.png)
Android自动化测试初探-5:再述模拟键盘鼠标事件(adb shell 实现)2010-07-28 17:01上一篇博文中讲述了通过Socket编程从外部向Emulator发送键盘鼠标模拟事件,貌似实现细节有点复杂。
其实Android还有一种更简单的模拟键盘鼠标事件的方法,那就是通过使用adb shell 命令。
1. 发送键盘事件:命令格式1:adb shell input keyevent “value”其中value以及对应的key code如下表所列:KeyEvent ValueKEYCODECommentKEYCODE_UNKNOWN1KEYCODE_MENU在SDK2.1的模拟器中命令失效,sendevent命令可行2KEYCODE_SOFT_RIGHT3KEYCODE_HOME4KEYCODE_BACK5KEYCODE_CALL6KEYCODE_ENDCALLKEYCODE_08 KEYCODE_19 KEYCODE_210 KEYCODE_311 KEYCODE_412 KEYCODE_513 KEYCODE_614 KEYCODE_715 KEYCODE_816 KEYCODE_917 KEYCODE_STARKEYCODE_POUND19KEYCODE_DPAD_UP20KEYCODE_DPAD_DOWN21KEYCODE_DPAD_LEFT22KEYCODE_DPAD_RIGHT23KEYCODE_DPAD_CENTER24KEYCODE_VOLUME_UP25KEYCODE_VOLUME_DOWN26KEYCODE_POWER27KEYCODE_CAMERA28KEYCODE_CLEARKEYCODE_A30 KEYCODE_B31 KEYCODE_C32 KEYCODE_D33 KEYCODE_E34 KEYCODE_F35 KEYCODE_G36 KEYCODE_H37 KEYCODE_I38 KEYCODE_J39 KEYCODE_KKEYCODE_L41 KEYCODE_M42 KEYCODE_N43 KEYCODE_O44 KEYCODE_P45 KEYCODE_Q46 KEYCODE_R47 KEYCODE_S48 KEYCODE_T49 KEYCODE_U50 KEYCODE_VKEYCODE_W52KEYCODE_X53KEYCODE_Y54KEYCODE_Z55KEYCODE_COMMA56KEYCODE_PERIOD57KEYCODE_ALT_LEFT58KEYCODE_ALT_RIGHT59KEYCODE_SHIFT_LEFT60KEYCODE_SHIFT_RIGHT61KEYCODE_TABKEYCODE_SPACE63KEYCODE_SYM64KEYCODE_EXPLORER65KEYCODE_ENVELOPE66KEYCODE_ENTER67KEYCODE_DEL68KEYCODE_GRAVE69KEYCODE_MINUS70KEYCODE_EQUALS71KEYCODE_LEFT_BRACKET72KEYCODE_RIGHT_BRACKETKEYCODE_BACKSLASH74KEYCODE_SEMICOLON75KEYCODE_APOSTROPHE76KEYCODE_SLASH77KEYCODE_AT78KEYCODE_NUM79KEYCODE_HEADSETHOOK80KEYCODE_FOCUS81KEYCODE_PLUS82KEYCODE_MENU83KEYCODE_NOTIFICATIONKEYCODE_SEARCH85TAG_LAST_KEYCODE命令格式2:adb shell sendevent [device] [type] [code] [value]如: adb shell sendevent /dev/input/event0 1 229 1 代表按下按下menu 键adb shell sendevent /dev/input/event0 1 229 0 代表按下松开menu 键说明:上述的命令需组合使用另外所知道的命令如下:Key Name CODEMENU 229HOME 102BACK (back button) 158CALL (call button) 231END (end call button) 1072. 发送鼠标事件(Touch):命令格式:adb shell sendevent [device] [type] [code] [value]情况1:在某坐标点上touch如在屏幕的x坐标为40,y坐标为210的点上touch一下,命令如下adb shell sendevent /dev/input/event0 3 0 40adb shell sendevent /dev/input/event0 3 1 210adb shell sendevent /dev/input/event0 1 330 1 //touchadb shell sendevent /dev/input/event0 0 0 0 //it must haveadb shell sendevent /dev/input/event0 1 330 0 //untouchadb shell sendevent /dev/input/event0 0 0 0 //it must have注:以上六组命令必须配合使用,缺一不可情况2:模拟滑动轨迹(可下载并采用aPaint软件进行试验)如下例是在aPaint软件上画出一条开始于(100,200),止于(108,200)的水平直线adb shell sendevent /dev/input/event0 3 0 100 //start from point (100,200)adb shell sendevent /dev/input/event0 3 1 200adb shell sendevent /dev/input/event0 1 330 1 //touchadb shell sendevent /dev/input/event0 0 0 0adb shell sendevent /dev/input/event0 3 0 101 //step to point (101,200)adb shell sendevent /dev/input/event0 0 0 0…………………… //m ust list each step, here just skipadb shell sendevent /dev/input/event0 3 0 108 //end point(108,200)adb shell sendevent /dev/input/event0 0 0 0adb shell sendevent /dev/input/event0 1 330 0 //untouchadb shell sendevent /dev/input/event0 0 0 0。
通过ADBshell在Android上模拟点击事件(头疼)
![通过ADBshell在Android上模拟点击事件(头疼)](https://img.taocdn.com/s3/m/0318eea185868762caaedd3383c4bb4cf7ecb7da.png)
通过ADBshell在Android上模拟点击事件(头疼)众所周知,Linux上可以通过sendEvent来模拟键盘或者鼠标点击事件。
而Android是基于Linux2.6平台的,所以也应该可以模拟点击事件,在很多网络文章中也有提到。
但是我在Motolola的Xoom,Android3.0系统上,试图通过adb -d shell sendevent /dev/input/event6 3 0 180adb -d shell sendevent /dev/input/event6 3 1 70adb -d shell sendevent /dev/input/event6 1 330 1adb -d shell sendevent /dev/input/event6 0 0 0adb -d shell sendevent /dev/input/event6 1 330 0adb -d shell sendevent /dev/input/event6 0 0 0来点击一个应用程序,发现无效。
但在模拟器的同一个位置是可以点击到的,所以怀疑有问题。
于是我分别用getevent来获取模拟器上点击的事件与在XOOM 上点击的事件,发现两者不同。
在模拟器上:得到的Event是 /dev/input/event0 3 0 180/dev/input/event0 3 1 70...........这6个事件在真机上,我用cat /proc/bus/input/devices对比了列出的内容,touchscreen是event6, 但是得到的event却是/dev/input/event6: 0003 0030 0000003c/dev/input/event6: 0003 0032 00000004/dev/input/event6: 0003 0035 000008b6/dev/input/event6: 0003 0036 000005ab/dev/input/event6: 0003 0034 000000f0/dev/input/event6: 0003 0039 00000000/dev/input/event6: 0000 0002 00000000/dev/input/event6: 0000 0000 00000000......等几十条事件我不明白,1. 为什么模拟器上点击一下只有固定6条格式,但是模拟器上出现了几十条2. 参考国内很多网络资料也说,用0003代表要控制绝对坐标,后面跟0或者1表示x或者y坐标,为什么这里却是更的0030,0032,0035,0036,0034,0039,0002这些信息??有哪位愿意指点,非常感谢附录:用cat获得的设备对应event信息# cat /proc/bus/input/devicescat /proc/bus/input/devicesI: Bus=0000 Vendor=0000 Product=0000 Version=0000N: Name="compass"P: Phys=S: Sysfs=/devices/virtual/input/input0U: Uniq=H: Handlers=event0B: EV=5B: REL=3f8I: Bus=0000 Vendor=0000 Product=0000 Version=0000 N: Name="accelerometer"P: Phys=S: Sysfs=/devices/virtual/input/input1U: Uniq=H: Handlers=event1B: EV=dB: REL=7B: ABS=100 7I: Bus=0000 Vendor=0000 Product=0000 Version=0000 N: Name="max9635_als"P: Phys=S: Sysfs=/devices/virtual/input/input2U: Uniq=H: Handlers=event2B: EV=11B: MSC=8I: Bus=0000 Vendor=0000 Product=0000 Version=0000 N: Name="gyroscope"P: Phys=S: Sysfs=/devices/virtual/input/input3U: Uniq=H: Handlers=event3B: EV=5B: REL=38I: Bus=0000 Vendor=0000 Product=0000 Version=0000 N: Name="barometer"P: Phys=S: Sysfs=/devices/virtual/input/input4U: Uniq=H: Handlers=event4B: EV=9B: ABS=1000000I: Bus=0000 Vendor=0000 Product=0000 Version=0000 N: Name="cpcap-key"P: Phys=S: Sysfs=/devices/virtual/input/input5U: Uniq=H: Handlers=event5 keyreset keyresetB: EV=3B: KEY=4 0 0 0 800 0 0 0I: Bus=0000 Vendor=0000 Product=0000 Version=0000 N: Name="qtouch-touchscreen"P: Phys=S: Sysfs=/devices/virtual/input/input6U: Uniq=H: Handlers=event6B: EV=bB: KEY=400 0 4 0 0 0 0 0 0 0 0B: ABS=2750000 11030003I: Bus=0000 Vendor=0000 Product=0000 Version=0000 N: Name="stingray-keypad"P: Phys=S: Sysfs=/devices/virtual/input/input7U: Uniq=H: Handlers=event7 keyreset keychordB: EV=3B: KEY=c0000 0 0 0。
input keyevent 原理
![input keyevent 原理](https://img.taocdn.com/s3/m/6f14f7286fdb6f1aff00bed5b9f3f90f76c64d31.png)
input keyevent 原理
input keyevent是Android系统的一个命令,用于模拟按键事件。
它的原理是向系统发送一个按键事件的请求,并由系统将该请求转发给当前活动(Activity)或焦点所在的窗口,来模拟用
户的按键操作。
具体步骤如下:
1. 应用程序或测试框架通过adb命令或Java代码调用input keyevent命令。
2. input keyevent命令会将按键事件的请求发送给
/system/bin/input命令,即InputManagerService。
3. InputManagerService根据接收到的按键事件,将其放入一个
队列中。
4. 当Activity或窗口焦点发生变化时,InputManagerService会
将队列中的按键事件发送到焦点对应的Activity或窗口。
5. Activity或窗口接收到按键事件后,根据具体键值进行相应
的处理,例如触发相应的回调函数或执行按键对应的操作。
6. 操作完成后,Activity或窗口会通过InputManagerService将
处理结果返回给InputManager。
总结来说,input keyevent的原理就是通过向系统发送按键事
件请求来模拟用户的按键操作。
系统接收到按键事件后,将其分发给对应的活动或窗口进行处理。
Android自动化测试工具常用ADB命令总结
![Android自动化测试工具常用ADB命令总结](https://img.taocdn.com/s3/m/aab8443da5e9856a561260a4.png)
自动化测试常用ADB命令操作总结自动化测试基本操作命令:模拟点击操作:adb shell input tap 500 500 (点击手机(500,500)坐标)模拟滑动屏幕操作:adb shell input swipe 200 500 400 500模拟输入文本信息:adb shell input text helloworld模拟按键命令:adb shell input keyeventKEYCODE_VOLNME_DOWN按音量下键adb shell input keyeventKEYCODE_VOLNME_UP 按音量上键adb shell input keyevent自动化测试中日志分析截图命令:数据线连接手机截图:adb shell /system/bin/screencap–p /sdcard/screenshot.png 将截图复制到电脑盘中:adb pull /sdcard/screenshot.png E:\download输出所有已经安装应用:adb shell pm list package –f查看预安APKadb shell pm list package -3安装应用程序:adb install –r 应用程序.apk文件传输:获取模拟器中的文件:adb pull <remote><local>向模拟器中写文件:adb push <local><remote>其他命令:重启手机:adb shell reboot重启手机进入recovery模式:adb shell reboot recovery 重启手机进入下载模式:adb shell reboot bootloader对某一模拟器执行命令:adb–s 模拟器编号命令常用的发送键盘事件:命令格式:adb shell input keyevent“value”其中value以及对应的key code如下:KeyEventValueKEYCODE0 KEYCODE_UNKNOWN1 KEYCODE_MENU2 KEYCODE_SOFT_RIGHT3 KEYCODE_HOME4 KEYCODE_BACK5 KEYCODE_CALL6 KEYCODE_ENDCALL7 KEYCODE_08 KEYCODE_19 KEYCODE_210 KEYCODE_311 KEYCODE_412 KEYCODE_513 KEYCODE_614 KEYCODE_715 KEYCODE_816 KEYCODE_917 KEYCODE_STAR18 KEYCODE_POUND19 KEYCODE_DPAD_UP20 KEYCODE_DPAD_DOWN21 KEYCODE_DPAD_LEFT22 KEYCODE_DPAD_RIGHT23 KEYCODE_DPAD_CENTER24 KEYCODE_VOLUME_UP25 KEYCODE_VOLUME_DOWN26 KEYCODE_POWER27 KEYCODE_CAMERA28 KEYCODE_CLEAR29 KEYCODE_A30 KEYCODE_B31 KEYCODE_C32 KEYCODE_D33 KEYCODE_E34 KEYCODE_F35 KEYCODE_G36 KEYCODE_H37 KEYCODE_I38 KEYCODE_J39 KEYCODE_K40 KEYCODE_L41 KEYCODE_M42 KEYCODE_N43 KEYCODE_O44 KEYCODE_P45 KEYCODE_Q46 KEYCODE_R47 KEYCODE_S48 KEYCODE_T49 KEYCODE_U50 KEYCODE_V51 KEYCODE_W52 KEYCODE_X53 KEYCODE_Y54 KEYCODE_Z55 KEYCODE_COMMA56 KEYCODE_PERIOD57 KEYCODE_ALT_LEFT58 KEYCODE_ALT_RIGHT59 KEYCODE_SHIFT_LEFT60 KEYCODE_SHIFT_RIGHT61 KEYCODE_TAB62 KEYCODE_SPACE63 KEYCODE_SYM64 KEYCODE_EXPLORER65 KEYCODE_ENVELOPE66 KEYCODE_ENTER67 KEYCODE_DEL68 KEYCODE_GRAVE69 KEYCODE_MINUS70 KEYCODE_EQUALS71 KEYCODE_LEFT_BRACKET72 KEYCODE_RIGHT_BRACKET73 KEYCODE_BACKSLASH74 KEYCODE_SEMICOLON75 KEYCODE_APOSTROPHE76 KEYCODE_SLASH77 KEYCODE_AT78 KEYCODE_NUM79 KEYCODE_HEADSETHOOK80 KEYCODE_FOCUS81 KEYCODE_PLUS82 KEYCODE_MENU83 KEYCODE_NOTIFICATION84 KEYCODE_SEARCH85 TAG_LAST_KEYCODE。
Shell和Python获取键盘事件
![Shell和Python获取键盘事件](https://img.taocdn.com/s3/m/5eb4080911a6f524ccbff121dd36a32d7375c73e.png)
Shell和Python获取键盘事件Shell和Python可以说是Linux环境中很常⽤的脚本语⾔了,可以⽅便地实现运维、测试等等⾃动化,减轻⼈的负担。
很多时候,脚本也需要和⽤户进⾏简单的交互,例如读取键盘输⼊。
响应键盘事件和读取输⼊还是不同的。
响应键盘事件指的是判断哪个按键被按下,⽤户按下某⼀按键后⽴即响应,例如按下q键⽴即退出程序。
⽽读取输⼊则⼀般是⽤户输⼊⼀⾏后,按下回车,则程序读⼊这⼀⾏字符串。
读取输⼊⽐较常⽤,在Shell中可以使⽤read,在Python中可以使⽤input()或者sys.stdin.readline()等。
如果需要实现对⽤户按下键盘按键的响应,可以通过以下⽅式实现。
ShellShell中可以⽤read实现按键检测(解释器使⽤bash)。
read -rsN1 input上述代码的含义是获取键盘按键,并存放到input中。
其中read的参数含义如下:-r:禁⽤转义字符。
-s:安静模式,不将输⼊显⽰出来。
例如按下按键A后,字母A不会显⽰在命令⾏⾥。
-N1:严格读取⼀个字符后结束,换⾏符也算⼀个字符。
这样就可以获取键盘按下的按键信息了。
例如,⽤户按下W、S、A、D四个按键后,显⽰前(Forward)后(Backward)左(Left)右(Right),按下Q键退出,代码如下:while true; doread -rsN1 inputif [[ "$input" == "w" ]]; thenecho "Forward"elif [[ "$input" == "s" ]]; thenecho "Backward"elif [[ "$input" == "a" ]]; thenecho "Left"elif [[ "$input" == "d" ]]; thenecho "Right"elif [[ "$input" == "q" ]]; thenecho "Quit!"breakelsecontinuefidone上⾯的代码也可以获取按下回车键的事件。
keybd_event,mouse_event模拟产生键盘事件、鼠标事件的使用
![keybd_event,mouse_event模拟产生键盘事件、鼠标事件的使用](https://img.taocdn.com/s3/m/16b7286a2a160b4e767f5acfa1c7aa00b42a9d41.png)
keybd_event,mouse_event模拟产生键盘事件、鼠标事件的使用比如一个应用:自动关闭弹出的Messagox对话框(/dijkstar/article/details/8761481)(2013-04-05编辑)void CSimulateMouseView::OnLdbclick(){//将鼠标的位置放在窗口的标题条上POINT lpPoint;CRect rc;CWnd* pParent = AfxGetApp()->GetMainWnd();pParent->GetWindowRect(&rc);lpPoint.x = rc.left+50;lpPoint.y = rc.top+10;SetCursorPos(lpPoint.x, lpPoint.y);//双击该标题条mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);}void CSimulateMouseView::OnLclick(){//将鼠标的位置放在窗口的关闭按钮上POINT lpPoint;CRect rc;CWnd* pParent = AfxGetApp()->GetMainWnd();pParent->GetWindowRect(&rc);lpPoint.x = rc.right-5;lpPoint.y = rc.top +5;SetCursorPos(lpPoint.x, lpPoint.y);//单击mouse_event(MOUSEEVENTF_LEFTDOWN|MOUSEEVENTF_ABSOLUTE,0,0,0,0);mouse_event(MOUSEEVENTF_LEFTUP|MOUSEEVENTF_ABS OLUTE,0,0,0,0);}BOOL CSimulateMouseView::PreTranslateMessage(MSG* pMsg){// TODO: Add your specialized code here and/or call the base classif (pMsg->message==WM_KEYDOWN && pMsg->wParam==0x41){::MessageBox(NULL, "A 键按下", "提示", MB_ICONQUESTION);return FALSE; //不翻译消息,直接将消息传递下去。
adb shell input keyevent 返回
![adb shell input keyevent 返回](https://img.taocdn.com/s3/m/3371b2e7294ac850ad02de80d4d8d15abe2300ac.png)
adb shell input keyevent 返回返回(Back)按键在手机操作中扮演着重要的角色,它可以帮助用户返回到上一个界面或退出当前的应用程序。
在本文中,我们将会探讨返回按键的使用和作用,并且提供一些有关返回按键的使用经验和技巧。
返回按键的作用返回按键的主要作用是帮助用户退回到上一个界面或退出当前的应用程序。
当用户在使用手机的过程中,通过不断地按下返回按键,可以回到之前的屏幕或关闭当前应用程序。
这种操作十分便捷,可以大大提高手机的使用效率。
一般来说,返回按键的作用有以下几个方面:1.回到上一个界面:当用户在一个应用程序中浏览内容或执行某项操作后,按下返回按键可以快速返回到上一个界面。
这样的操作可以帮助用户快速回到之前的屏幕,十分方便实用。
2.退出当前应用程序:当用户需要退出当前应用程序时,按下返回按键可以迅速关闭该应用程序。
这样的操作可以帮助用户快速退出当前界面,节省系统资源。
3.返回桌面:如果用户希望直接返回到手机的桌面界面,可以通过多次按下返回按键实现此目标。
这样的操作可以帮助用户快速回到手机主屏幕,方便进行其他操作。
返回按键的使用返回按键的使用非常简单,只需要按下设备上的返回按键即可。
在大多数手机上,返回按键通常位于手机的底部,中间或右下角。
可以根据手机型号和厂商的设计来确定具体的位置。
在使用返回按键时,有一些简单的技巧和经验可以帮助用户提高效率:1.单击返回按键:单击返回按键可以帮助用户快速地返回到上一个界面。
这种操作特别适用于在一个应用程序中查看内容时,只需要按下返回按键即可回到之前的屏幕。
2.多次点击返回按键:多次点击返回按键可以帮助用户退出当前应用程序或直接返回到手机的桌面界面。
只需要连续点击返回按键几次,就可以实现这一目标。
3.长按返回按键:长按返回按键可以帮助用户打开最近的应用程序列表。
当长时间按住返回按键时,手机会显示最近使用的应用程序,用户只需要选择所需的应用程序即可打开。
Python捕捉和模拟鼠标事件的方法
![Python捕捉和模拟鼠标事件的方法](https://img.taocdn.com/s3/m/c0d6b27726d3240c844769eae009581b6bd9bde7.png)
Python捕捉和模拟⿏标事件的⽅法本⽂实例讲述了Python捕捉和模拟⿏标事件的⽅法。
分享给⼤家供⼤家参考。
具体分析如下:这个假期玩了不少galgame,不过有些很⽼的游戏没有⾃动运⾏模式,点击⿏标⼜太伤按键了,于是想把滚动⿏标滚轮映射为点击⿏标。
⽹上搜了⼀下,没发现什么现成的软件,⽽按键精灵⼜太重量级了,于是考虑⼲脆⾃⼰⽤Python写个算了。
这⾥需要把PyHook和PyWin32都装上(建议下exe版,免得安装时各种蛋疼)。
翻了翻教程,发现实现起来很简单:# -*- coding: utf-8 -*-import pythoncom, pyHookdef OnMouseEvent(event):print 'MessageName:',event.MessageNameprint 'Message:',event.Messageprint 'Time:',event.Timeprint 'Window:',event.Windowprint 'WindowName:',event.WindowNameprint 'Position:',event.Positionprint 'Wheel:',event.Wheelprint 'Injected:',event.Injectedprint '---'# 返回 True 可将事件传给其它处理程序,否则停⽌传播事件return True# 创建钩⼦管理对象hm = pyHook.HookManager()# 监听所有⿏标事件hm.MouseAll = OnMouseEvent # 等效于hm.SubscribeMouseAll(OnMouseEvent)# 开始监听⿏标事件hm.HookMouse()# ⼀直监听,直到⼿动退出程序pythoncom.PumpMessages()这个例⼦程序捕捉了所有的⿏标事件,实际上我只需要捕捉向下滚动滚轮的事件即可。
adb shell input keyevent 返回
![adb shell input keyevent 返回](https://img.taocdn.com/s3/m/82f71466bdd126fff705cc1755270722192e59ed.png)
adb shell input keyevent 返回
`adb shell input keyevent` 是Android Debug Bridge(ADB)工具的一部分,用于通过命令行向Android 设备发送按键事件。
不同的按键事件对应不同的键码(key code)。
如果你使用`adb shell input keyevent` 命令发送按键事件后,终端可能没有明确的返回信息。
如果你想查看键码是否被正确发送,可以尝试在命令行中添加`echo $?`,它将显示上一个命令的退出代码。
如果命令成功执行,退出代码通常是0。
例如:
```bash
adb shell input keyevent 26
echo $?
```
上述例子中,`keyevent 26` 代表的是电源按钮,执行完这个命令后,如果一切正常,`echo $?` 应该返回0。
请注意,不同的Android 版本和设备可能对键码的处理方式有所不同,因此确保你使用的键码是适用于你的设备和需求的。
你可以在Android 官方文档中查找键码对应关系。
总的来说,`adb shell input keyevent` 命令没有明确的返回,而是通过观察设备的行为来验证按键事件是否成功发送。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Android自动化测试初探-5:再述模拟键盘鼠标事件(adb shell 实现)
2010-07-28 17:01
上一篇博文中讲述了通过Socket编程从外部向Emulator发送键盘鼠标模拟事件,貌似实现细节有点复杂。
其实Android还有一种更简单的模拟键盘鼠标事件的方法,那就是通过使用adb shell 命令。
1. 发送键盘事件:
命令格式1:adb shell input keyevent “value”
其中value以及对应的key code如下表所列:
KeyEvent Value
KEYCODE
Comment
KEYCODE_UNKNOWN
1
KEYCODE_MENU
在SDK2.1的模拟器中命令失效,sendevent命令可行
2
KEYCODE_SOFT_RIGHT
3
KEYCODE_HOME
4
KEYCODE_BACK
5
KEYCODE_CALL
6
KEYCODE_ENDCALL
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
KEYCODE_POUND
19
KEYCODE_DPAD_UP
20
KEYCODE_DPAD_DOWN
21
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
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
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
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
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
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
KEYCODE_SEARCH
85
TAG_LAST_KEYCODE
命令格式2:adb shell sendevent [device] [type] [code] [value]
如: adb shell sendevent /dev/input/event0 1 229 1 代表按下按下menu 键
adb shell sendevent /dev/input/event0 1 229 0 代表按下松开menu 键
说明:上述的命令需组合使用
另外所知道的命令如下:
Key Name CODE
MENU 229
HOME 102
BACK (back button) 158
CALL (call button) 231
END (end call button) 107
2. 发送鼠标事件(Touch):
命令格式:adb shell sendevent [device] [type] [code] [value]
情况1:在某坐标点上touch
如在屏幕的x坐标为40,y坐标为210的点上touch一下,命令如下
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 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
注:以上六组命令必须配合使用,缺一不可
情况2:模拟滑动轨迹(可下载并采用aPaint软件进行试验)
如下例是在aPaint软件上画出一条开始于(100,200),止于(108,200)的水平直线
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 330 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
…………………… //m ust list each step, here just skip
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 330 0 //untouch
adb shell sendevent /dev/input/event0 0 0 0。