在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. */
public static final int KEYCODE_POWER = 26;
/** Key code constant: Camera key.
* Used to launch a camera application or take pictures. */
public static final int KEYCODE_CAMERA = 27;
/** 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. */
public static final int KEYCODE_ENTER = 66;
/** Key code constant: Backspace key.
* Deletes characters before the insertion point, unlike {@link #KEYCODE_FORWARD_DEL}. */
public static final int KEYCODE_DEL = 67;
/** 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. */
public static final int KEYCODE_BUTTON_X = 99;
/** Key code constant: Y Button key.
* On a game controller, the Y button should be either the button labeled Y
* or the second button on the upper row of controller buttons. */
public static final int KEYCODE_BUTTON_Y = 100;
/** 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.
* May be used to close a CD tray, for example. */
public static final int KEYCODE_MEDIA_CLOSE = 128;
/** Key code constant: Eject media key.
* May be used to eject a CD tray, for example. */
public static final int KEYCODE_MEDIA_EJECT = 129;
/** 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: Channel up key.
* On TV remotes, increments the television channel. */
public static final int KEYCODE_CHANNEL_UP = 166;
/** Key code constant: Channel down key.
* On TV remotes, decrements the television channel. */
public static final int KEYCODE_CHANNEL_DOWN = 167;
/** 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 #11.*/
public static final int KEYCODE_BUTTON_11 = 198;
/** Key code constant: Generic Game Pad Button #12.*/
public static final int KEYCODE_BUTTON_12 = 199;
/** Key code constant: Generic Game Pad Button #13.*/
public static final int KEYCODE_BUTTON_13 = 200;
/** 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. */
public static final int KEYCODE_12 = 228;
/** Key code constant: Last Channel key.
* Goes to the last viewed channel. */
public static final int KEYCODE_LAST_CHANNEL = 229;
/** Key code constant: TV data service 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;
/** Key code constant: Contents menu key.
* Goes to the title list. Corresponds to Contents Menu (0x0B) of CEC User Control
* Code */
public static final int KEYCODE_TV_CONTENTS_MENU = 256;
/** Key code constant: Media context menu key.
* Goes to the context menu of media contents. Corresponds to Media Context-sensitive
* Menu (0x11) of CEC User Control Code. */
public static final int KEYCODE_TV_MEDIA_CONTEXT_MENU = 257;
/** Key code constant: Timer programming key.
* Goes to the timer recording menu. Corresponds to Timer Programming (0x54) of
* CEC User Control Code. */
public static final int KEYCODE_TV_TIMER_PROGRAMMING = 258;
/** Key code constant: Help key. */
public static final int KEYCODE_HELP = 259;
/** Key code constant: Navigate to previous key.
* Goes backward by one item in an ordered collection of items. */
public static final int KEYCODE_NAVIGATE_PREVIOUS = 260;
/** Key code constant: Navigate to next key.
* Advances to the next item in an ordered collection of items. */
public static final int KEYCODE_NAVIGATE_NEXT = 261;
/** Key code constant: Navigate in key.
* Activates the item that currently has focus or expands to the next level of a navigation
* hierarchy. */
public static final int KEYCODE_NAVIGATE_IN = 262;
/** Key code constant: Navigate out key.
* Backs out one level of a navigation hierarchy or collapses the item that currently has
* focus. */
public static final int KEYCODE_NAVIGATE_OUT = 263;
/** Key code constant: Skip forward media key. */
public static final int KEYCODE_MEDIA_SKIP_FORWARD = 272;
/** Key code constant: Skip backward media key. */
public static final int KEYCODE_MEDIA_SKIP_BACKWARD = 273;
/** Key code constant: Step forward media key.
* Steps media forward, one frame at a time. */
public static final int KEYCODE_MEDIA_STEP_FORWARD = 274;
/** Key code constant: Step backward media key.
* Steps media backward, one frame at a time. */
public static final int KEYCODE_MEDIA_STEP_BACKWARD = 275;

常用 keycode 列表

keycode    含义
HOME 键
返回键
打开拨号应用
挂断电话
增加音量
降低音量
电源键
拍照(需要在相机应用里)
打开浏览器
菜单键
播放/暂停
停止播放
播放下一首
播放上一首
移动光标到行首或列表顶部
移动光标到行末或列表底部
恢复播放
暂停播放
静音
打开系统设置
切换应用
打开联系人
打开日历
打开音乐
打开计算器
降低屏幕亮度
提高屏幕亮度
系统休眠
点亮屏幕
打开语音助手
如果没有 wakelock 则让系统休眠

input 命令的一些用法举例

电源键
命令:

adb shell input keyevent 

执行效果相当于按电源键。

菜单键
命令:

adb shell input keyevent 

HOME 键
命令:

  adb shell input keyevent 3

返回键
命令:

  adb shell input keyevent 4

音量控制
增加音量:

  adb shell input keyevent 24

降低音量:

  adb shell input keyevent 25

静音:

  adb shell input keyevent 164

媒体控制

播放/暂停:

  adb shell input keyevent 85

停止播放:

  adb shell input keyevent 86

播放下一首:

  adb shell input keyevent 87

播放上一首:

  adb shell input keyevent 88

恢复播放:

  adb shell input keyevent 126

暂停播放:

  adb shell input keyevent 127

点亮/熄灭屏幕

可以通过上文讲述过的模拟电源键来切换点亮和熄灭屏幕,但如果明确地想要点亮或者熄灭屏幕,那可以使用如下方法。

点亮屏幕:

  adb shell input keyevent 224

熄灭屏幕:

  adb shell input keyevent 223

python调用

# -*- coding: utf-8 -*-

#DEVICE_NAME = "172.16.71.95:5555"
#DEVICE_NAME = "SQRNW17A25006944"
#DEVICE_NAME = "ML5RROBJJB"
# DEVICE_NAME = "0123456789ABCDEF"
DEVICE_NAME = "" def get_device_name_param():
if DEVICE_NAME == "":
return ""
return " -s {0} ".format(DEVICE_NAME) def device_back_key():
device_input_key(4) def device_input_key(keycode):
#input命令格式 adb shell input keyevent <keycode>
cmd = "adb {0} shell input keyevent {1}".format(get_device_name_param(),keycode)
print(cmd)
os.system(cmd)
# -*- coding: utf-8 -*-
import os class keyevent():
'''常用的keyevent事件'''
KEYCODE_HOME = 3 #HOME键
KEYCODE_BACK = 4 #返回键
KEYCODE_CALL = 5 #打开拨号应用
KEYCODE_ENDCALL = 6 #挂断电话
KEYCODE_VOLUME_UP = 24#增加音量
KEYCODE_VOLUME_DOWN = 25#降低音量
KEYCODE_POWER = 26#电源键
KEYCODE_CAMERA = 27#拍照(需要在相机应用里)
KEYCODE_EXPLORER = 64#打开浏览器
KEYCODE_MENU = 82#菜单键
KEYCODE_MEDIA_PLAY_PAUSE= 85#播放 / 暂停
KEYCODE_MEDIA_STOP = 86#停止播放
KEYCODE_MEDIA_NEXT = 87#播放下一首
KEYCODE_MEDIA_PREVIOUS = 88#播放上一首
KEYCODE_MOVE_HOME = 122#移动光标到行首或列表顶部
KEYCODE_MOVE_END = 123#移动光标到行末或列表底部
KEYCODE_MEDIA_PLAY = 126#恢复播放
KEYCODE_MEDIA_PAUSE = 127#暂停播放 def adb_shell_input_keyevent(keycode=keyevent.KEYCODE_BACK):
#cmd = "adb shell input keyevent %s".format(keycode)
cmd = 'adb shell input keyevent {0}' %keycode
os.system(cmd) if __name__ == "__main__":
adb_shell_input_keyevent(keyevent.KEYCODE_BACK)

adb shell命令模拟按键/输入input使用keycode 列表详解的更多相关文章

  1. adb命令模拟按键输入keycode

    adb命令模拟按键输入keycode 2017年05月18日 14:57:32 阅读数:1883 例子: //这条命令相当于按了设备的Backkey键 adb shell input keyevent ...

  2. 【android】android 常用adb 和 adb shell 命令

    db是SDK自带的工具,可实现桥接功能:adb shell 可以与手机系统建立交互,是基于andoid Linux系统下的操作 ADB常用命令: 1. 查看设备         adb  device ...

  3. ubuntu 使用adb shell命令识别android设备

    ubuntu 使用adb shell命令配置 在ubuntu下使用adb 命令识别Android设备需配置adb_usb.ini 文件 文件路径:  ~/.android/ ,若不存在创建该文件. a ...

  4. 【原创】Android开发之ADB及ADB SHELl命令的应用

    adb的全称为Android Debug Bridge,就是起到调试桥的作用.通过adb我们可以在Eclipse中方面通过DDMS来调试Android程序,说白了就是debug工具.adb的工作方式比 ...

  5. adb shell 命令详解,android

    http://www.miui.com/article-275-1.html http://noobjava.iteye.com/blog/1914348 adb shell 命令详解,android ...

  6. 【安卓手机通用】android adb shell 命令大全

    浏览:3116 | 更新:2013-10-17 17:05 | 标签:安卓 android 一.[什么是shell] Linux系统的shell作为操作系统的外壳,为用户提供使用操作系统的接口.它是命 ...

  7. adb shell命令后出现error: device not found错误提示

    在cmd中输入adb shell进入linux shell环境前,需要把android模拟器打开(本文都是针对模拟器而言,并非真机).如果启动好了模拟器,且输入adb shell命令后出现error: ...

  8. linux下如何模拟按键输入和模拟鼠标【转】

    转自:http://www.cnblogs.com/leaven/archive/2010/11/30/1891947.html 查看/dev/input/eventX是什么类型的事件, cat /p ...

  9. adb shell 命令详解,android, adb logcat

    http://www.miui.com/article-275-1.html http://noobjava.iteye.com/blog/1914348 adb shell 命令详解,android ...

随机推荐

  1. Mac下破解百度网盘限速(Chrome + Aria2GUI)

    基本原理是利用Aria2GUI的多线程下载来达到提速的目的,具体步骤如下: 1.下载Aria2GUI客户端(注意,客户端文件要放入‘应用程序’,否则会报错),使用时注意修改线程数,默认为16,不够用, ...

  2. python异常处理--try except else raise finally

    转载自https://www.cnblogs.com/bokeyuan11/p/9146607.html 写程序时遇到异常情况,程序可能无法正常运行.此时就需要引入异常处理 1.try ...exce ...

  3. 【MAC】图片编辑工具-合成图片

    MAC中和wIn环境中画图一样的工具,可以对图片进行编辑 step1: step2: step3: 从工具栏中选择你要使用的工具,进行对应的操作. step4: 合成图片: 效果如图:

  4. XAMPP安装后启动Apache的Busy解决方法

    启动apache后,一直提示80 busy 使用netstat -ano查看,并无端口占用,真是奇怪. 百度之后发现有可能是启动后,ssl端口占用导致. XAMPP默认会加载一个SSL模块,它要占用一 ...

  5. Thymeleaf 页面表达式基础

    转自:http://www.cnblogs.com/vinphy/p/4674247.html#undefined (一)Thymeleaf 是个什么?      简单说, Thymeleaf 是一个 ...

  6. 物料批量盘点,调用其中两个BAPI BAPI_MATPHYSINV_COUNT BAPI_MATPHYSINV_CHANGECOUNT

    涉及两个BAPI:录入数量BAPI_MATPHYSINV_COUNT 修改数量:BAPI_MATPHYSINV_CHANGECOUNT REPORT  ZSC_133 NO STANDARD PAGE ...

  7. Unity 相机

    相机属性 1.相机的Clear属性:Skybo背景会渲染天空盒:solid color背景为颜色:depth only仅仅深度,相当于优先级:Don`t Clear背景是上一帧的图像:2.Projec ...

  8. 英特尔® Open Image Denoise 库有助于节省时间,提高质量

    在使用光线跟踪增强真实性与沉浸感时,游戏开发人员面临复杂的权衡.为了克服一系列挑战,英特尔创建了使用光线跟踪进行图像渲染的一整套解决方案,包含高性能开源滤波器.该解决方案已发布测试版,被集成至 Uni ...

  9. vue中,基于echarts 地图实现一个人才回流的大数据展示效果

    0.引入echarts组件,和中国地图js import eCharts from 'echarts' import 'echarts/map/js/china.js'// 引入中国地图 1. 设置地 ...

  10. python+selenium下载文件——Chrome

    from selenium import webdriver import time options = webdriver.ChromeOptions() prefs = { 'profile.de ...