本章开始介绍下Monkeyrunner的API, 以便了解其具体的使用。
void press (string name, dictionary type) : 可以说是对键盘的操作
Sends the key event specified by type to the key specified by keycode.
Sends the key event specified by type
to the key specified by keycode
.
name | The name of the keycode to send. See KeyEvent for a list of keycode names. Use the keycode name, not its integer value. |
---|---|
type | The type of key event to send. The allowed values are DOWN , UP , and DOWN_AND_UP . |
E.g. 点击menu按钮
device.press('KEYCODE_MENU', MonkeyDevice.DOWN_AND_UP)
KeyEvent:
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | ACTION_DOWN | getAction() value: the key has been pressed down. |
|||||||||
int | ACTION_MULTIPLE | getAction() value: multiple duplicate key events have occurred in a row, or a complex string is being delivered. |
|||||||||
int | ACTION_UP | getAction() value: the key has been released. |
|||||||||
int | FLAG_CANCELED | When associated with up key events, this indicates that the key press has been canceled. | |||||||||
int | FLAG_CANCELED_LONG_PRESS | Set when a key event has FLAG_CANCELED set because a long press action was executed while it was down. |
|||||||||
int | FLAG_EDITOR_ACTION | This mask is used for compatibility, to identify enter keys that are coming from an IME whose enter key has been auto-labelled "next" or "done". | |||||||||
int | FLAG_FALLBACK | Set when a key event has been synthesized to implement default behavior for an event that the application did not handle. | |||||||||
int | FLAG_FROM_SYSTEM | This mask is set if an event was known to come from a trusted part of the system. | |||||||||
int | FLAG_KEEP_TOUCH_MODE | This mask is set if we don't want the key event to cause us to leave touch mode. | |||||||||
int | FLAG_LONG_PRESS | This flag is set for the first key repeat that occurs after the long press timeout. | |||||||||
int | FLAG_SOFT_KEYBOARD | This mask is set if the key event was generated by a software keyboard. | |||||||||
int | FLAG_TRACKING | Set for ACTION_UP when this event's key code is still being tracked from its initial down. |
|||||||||
int | FLAG_VIRTUAL_HARD_KEY | This key event was generated by a virtual (on-screen) hard key area. | |||||||||
int | FLAG_WOKE_HERE | This mask is set if the device woke because of this key event. | |||||||||
int | KEYCODE_0 | Key code constant: '0' key. | |||||||||
int | KEYCODE_1 | Key code constant: '1' key. | |||||||||
int | KEYCODE_2 | Key code constant: '2' key. | |||||||||
int | KEYCODE_3 | Key code constant: '3' key. | |||||||||
int | KEYCODE_3D_MODE | Key code constant: 3D Mode key. | |||||||||
int | KEYCODE_4 | Key code constant: '4' key. | |||||||||
int | KEYCODE_5 | Key code constant: '5' key. | |||||||||
int | KEYCODE_6 | Key code constant: '6' key. | |||||||||
int | KEYCODE_7 | Key code constant: '7' key. | |||||||||
int | KEYCODE_8 | Key code constant: '8' key. | |||||||||
int | KEYCODE_9 | Key code constant: '9' key. | |||||||||
int | KEYCODE_A | Key code constant: 'A' key. | |||||||||
int | KEYCODE_ALT_LEFT | Key code constant: Left Alt modifier key. | |||||||||
int | KEYCODE_ALT_RIGHT | Key code constant: Right Alt modifier key. | |||||||||
int | KEYCODE_APOSTROPHE | Key code constant: ''' (apostrophe) key. | |||||||||
int | KEYCODE_APP_SWITCH | Key code constant: App switch key. | |||||||||
int | KEYCODE_AT | Key code constant: '@' key. | |||||||||
int | KEYCODE_AVR_INPUT | Key code constant: A/V Receiver input key. | |||||||||
int | KEYCODE_AVR_POWER | Key code constant: A/V Receiver power key. | |||||||||
int | KEYCODE_B | Key code constant: 'B' key. | |||||||||
int | KEYCODE_BACK | Key code constant: Back key. | |||||||||
int | KEYCODE_BACKSLASH | Key code constant: '\' key. | |||||||||
int | KEYCODE_BOOKMARK | Key code constant: Bookmark key. | |||||||||
int | KEYCODE_BREAK | Key code constant: Break / Pause key. | |||||||||
int | KEYCODE_BUTTON_1 | Key code constant: Generic Game Pad Button #1. | |||||||||
int | KEYCODE_BUTTON_10 | Key code constant: Generic Game Pad Button #10. | |||||||||
int | KEYCODE_BUTTON_11 | Key code constant: Generic Game Pad Button #11. | |||||||||
int | KEYCODE_BUTTON_12 | Key code constant: Generic Game Pad Button #12. | |||||||||
int | KEYCODE_BUTTON_13 | Key code constant: Generic Game Pad Button #13. | |||||||||
int | KEYCODE_BUTTON_14 | Key code constant: Generic Game Pad Button #14. | |||||||||
int | KEYCODE_BUTTON_15 | Key code constant: Generic Game Pad Button #15. | |||||||||
int | KEYCODE_BUTTON_16 | Key code constant: Generic Game Pad Button #16. | |||||||||
int | KEYCODE_BUTTON_2 | Key code constant: Generic Game Pad Button #2. | |||||||||
int | KEYCODE_BUTTON_3 | Key code constant: Generic Game Pad Button #3. | |||||||||
int | KEYCODE_BUTTON_4 | Key code constant: Generic Game Pad Button #4. | |||||||||
int | KEYCODE_BUTTON_5 | Key code constant: Generic Game Pad Button #5. | |||||||||
int | KEYCODE_BUTTON_6 | Key code constant: Generic Game Pad Button #6. | |||||||||
int | KEYCODE_BUTTON_7 | Key code constant: Generic Game Pad Button #7. | |||||||||
int | KEYCODE_BUTTON_8 | Key code constant: Generic Game Pad Button #8. | |||||||||
int | KEYCODE_BUTTON_9 | Key code constant: Generic Game Pad Button #9. | |||||||||
int | KEYCODE_BUTTON_A | Key code constant: A Button key. | |||||||||
int | KEYCODE_BUTTON_B | Key code constant: B Button key. | |||||||||
int | KEYCODE_BUTTON_C | Key code constant: C Button key. | |||||||||
int | KEYCODE_BUTTON_L1 | Key code constant: L1 Button key. | |||||||||
int | KEYCODE_BUTTON_L2 | Key code constant: L2 Button key. | |||||||||
int | KEYCODE_BUTTON_MODE | Key code constant: Mode Button key. | |||||||||
int | KEYCODE_BUTTON_R1 | Key code constant: R1 Button key. | |||||||||
int | KEYCODE_BUTTON_R2 | Key code constant: R2 Button key. | |||||||||
int | KEYCODE_BUTTON_SELECT | Key code constant: Select Button key. | |||||||||
int | KEYCODE_BUTTON_START | Key code constant: Start Button key. | |||||||||
int | KEYCODE_BUTTON_THUMBL | Key code constant: Left Thumb Button key. | |||||||||
int | KEYCODE_BUTTON_THUMBR | Key code constant: Right Thumb Button key. | |||||||||
int | KEYCODE_BUTTON_X | Key code constant: X Button key. | |||||||||
int | KEYCODE_BUTTON_Y | Key code constant: Y Button key. | |||||||||
int | KEYCODE_BUTTON_Z | Key code constant: Z Button key. | |||||||||
int | KEYCODE_C | Key code constant: 'C' key. | |||||||||
int | KEYCODE_CALCULATOR | Key code constant: Calculator special function key. | |||||||||
int | KEYCODE_CALENDAR | Key code constant: Calendar special function key. | |||||||||
int | KEYCODE_CALL | Key code constant: Call key. | |||||||||
int | KEYCODE_CAMERA | Key code constant: Camera key. | |||||||||
int | KEYCODE_CAPS_LOCK | Key code constant: Caps Lock key. | |||||||||
int | KEYCODE_CAPTIONS | Key code constant: Toggle captions key. | |||||||||
int | KEYCODE_CHANNEL_DOWN | Key code constant: Channel down key. | |||||||||
int | KEYCODE_CHANNEL_UP | Key code constant: Channel up key. | |||||||||
int | KEYCODE_CLEAR | Key code constant: Clear key. | |||||||||
int | KEYCODE_COMMA | Key code constant: ',' key. | |||||||||
int | KEYCODE_CONTACTS | Key code constant: Contacts special function key. | |||||||||
int | KEYCODE_CTRL_LEFT | Key code constant: Left Control modifier key. | |||||||||
int | KEYCODE_CTRL_RIGHT | Key code constant: Right Control modifier key. | |||||||||
int | KEYCODE_D | Key code constant: 'D' key. | |||||||||
int | KEYCODE_DEL | Key code constant: Backspace key. | |||||||||
int | KEYCODE_DPAD_CENTER | Key code constant: Directional Pad Center key. | |||||||||
int | KEYCODE_DPAD_DOWN | Key code constant: Directional Pad Down key. | |||||||||
int | KEYCODE_DPAD_LEFT | Key code constant: Directional Pad Left key. | |||||||||
int | KEYCODE_DPAD_RIGHT | Key code constant: Directional Pad Right key. | |||||||||
int | KEYCODE_DPAD_UP | Key code constant: Directional Pad Up key. | |||||||||
int | KEYCODE_DVR | Key code constant: DVR key. | |||||||||
int | KEYCODE_E | Key code constant: 'E' key. | |||||||||
int | KEYCODE_ENDCALL | Key code constant: End Call key. | |||||||||
int | KEYCODE_ENTER | Key code constant: Enter key. | |||||||||
int | KEYCODE_ENVELOPE | Key code constant: Envelope special function key. | |||||||||
int | KEYCODE_EQUALS | Key code constant: '=' key. | |||||||||
int | KEYCODE_ESCAPE | Key code constant: Escape key. | |||||||||
int | KEYCODE_EXPLORER | Key code constant: Explorer special function key. | |||||||||
int | KEYCODE_F | Key code constant: 'F' key. | |||||||||
int | KEYCODE_F1 | Key code constant: F1 key. | |||||||||
int | KEYCODE_F10 | Key code constant: F10 key. | |||||||||
int | KEYCODE_F11 | Key code constant: F11 key. | |||||||||
int | KEYCODE_F12 | Key code constant: F12 key. | |||||||||
int | KEYCODE_F2 | Key code constant: F2 key. | |||||||||
int | KEYCODE_F3 | Key code constant: F3 key. | |||||||||
int | KEYCODE_F4 | Key code constant: F4 key. | |||||||||
int | KEYCODE_F5 | Key code constant: F5 key. | |||||||||
int | KEYCODE_F6 | Key code constant: F6 key. | |||||||||
int | KEYCODE_F7 | Key code constant: F7 key. | |||||||||
int | KEYCODE_F8 | Key code constant: F8 key. | |||||||||
int | KEYCODE_F9 | Key code constant: F9 key. | |||||||||
int | KEYCODE_FOCUS | Key code constant: Camera Focus key. | |||||||||
int | KEYCODE_FORWARD | Key code constant: Forward key. | |||||||||
int | KEYCODE_FORWARD_DEL | Key code constant: Forward Delete key. | |||||||||
int | KEYCODE_FUNCTION | Key code constant: Function modifier key. | |||||||||
int | KEYCODE_G | Key code constant: 'G' key. | |||||||||
int | KEYCODE_GRAVE | Key code constant: '`' (backtick) key. | |||||||||
int | KEYCODE_GUIDE | Key code constant: Guide key. | |||||||||
int | KEYCODE_H | Key code constant: 'H' key. | |||||||||
int | KEYCODE_HEADSETHOOK | Key code constant: Headset Hook key. | |||||||||
int | KEYCODE_HOME | Key code constant: Home key. | |||||||||
int | KEYCODE_I | Key code constant: 'I' key. | |||||||||
int | KEYCODE_INFO | Key code constant: Info key. | |||||||||
int | KEYCODE_INSERT | Key code constant: Insert key. | |||||||||
int | KEYCODE_J | Key code constant: 'J' key. | |||||||||
int | KEYCODE_K | Key code constant: 'K' key. | |||||||||
int | KEYCODE_L | Key code constant: 'L' key. | |||||||||
int | KEYCODE_LANGUAGE_SWITCH | Key code constant: Language Switch key. | |||||||||
int | KEYCODE_LEFT_BRACKET | Key code constant: '[' key. | |||||||||
int | KEYCODE_M | Key code constant: 'M' key. | |||||||||
int | KEYCODE_MANNER_MODE | Key code constant: Manner Mode key. | |||||||||
int | KEYCODE_MEDIA_CLOSE | Key code constant: Close media key. | |||||||||
int | KEYCODE_MEDIA_EJECT | Key code constant: Eject media key. | |||||||||
int | KEYCODE_MEDIA_FAST_FORWARD | Key code constant: Fast Forward media key. | |||||||||
int | KEYCODE_MEDIA_NEXT | Key code constant: Play Next media key. | |||||||||
int | KEYCODE_MEDIA_PAUSE | Key code constant: Pause media key. | |||||||||
int | KEYCODE_MEDIA_PLAY | Key code constant: Play media key. | |||||||||
int | KEYCODE_MEDIA_PLAY_PAUSE | Key code constant: Play/Pause media key. | |||||||||
int | KEYCODE_MEDIA_PREVIOUS | Key code constant: Play Previous media key. | |||||||||
int | KEYCODE_MEDIA_RECORD | Key code constant: Record media key. | |||||||||
int | KEYCODE_MEDIA_REWIND | Key code constant: Rewind media key. | |||||||||
int | KEYCODE_MEDIA_STOP | Key code constant: Stop media key. | |||||||||
int | KEYCODE_MENU | Key code constant: Menu key. | |||||||||
int | KEYCODE_META_LEFT | Key code constant: Left Meta modifier key. | |||||||||
int | KEYCODE_META_RIGHT | Key code constant: Right Meta modifier key. | |||||||||
int | KEYCODE_MINUS | Key code constant: '-'. | |||||||||
int | KEYCODE_MOVE_END | Key code constant: End Movement key. | |||||||||
int | KEYCODE_MOVE_HOME | Key code constant: Home Movement key. | |||||||||
int | KEYCODE_MUSIC | Key code constant: Music special function key. | |||||||||
int | KEYCODE_MUTE | Key code constant: Mute key. | |||||||||
int | KEYCODE_N | Key code constant: 'N' key. | |||||||||
int | KEYCODE_NOTIFICATION | Key code constant: Notification key. | |||||||||
int | KEYCODE_NUM | Key code constant: Number modifier key. | |||||||||
int | KEYCODE_NUMPAD_0 | Key code constant: Numeric keypad '0' key. | |||||||||
int | KEYCODE_NUMPAD_1 | Key code constant: Numeric keypad '1' key. | |||||||||
int | KEYCODE_NUMPAD_2 | Key code constant: Numeric keypad '2' key. | |||||||||
int | KEYCODE_NUMPAD_3 | Key code constant: Numeric keypad '3' key. | |||||||||
int | KEYCODE_NUMPAD_4 | Key code constant: Numeric keypad '4' key. | |||||||||
int | KEYCODE_NUMPAD_5 | Key code constant: Numeric keypad '5' key. | |||||||||
int | KEYCODE_NUMPAD_6 | Key code constant: Numeric keypad '6' key. | |||||||||
int | KEYCODE_NUMPAD_7 | Key code constant: Numeric keypad '7' key. | |||||||||
int | KEYCODE_NUMPAD_8 | Key code constant: Numeric keypad '8' key. | |||||||||
int | KEYCODE_NUMPAD_9 | Key code constant: Numeric keypad '9' key. | |||||||||
int | KEYCODE_NUMPAD_ADD | Key code constant: Numeric keypad '+' key (for addition). | |||||||||
int | KEYCODE_NUMPAD_COMMA | Key code constant: Numeric keypad ',' key (for decimals or digit grouping). | |||||||||
int | KEYCODE_NUMPAD_DIVIDE | Key code constant: Numeric keypad '/' key (for division). | |||||||||
int | KEYCODE_NUMPAD_DOT | Key code constant: Numeric keypad '.' key (for decimals or digit grouping). | |||||||||
int | KEYCODE_NUMPAD_ENTER | Key code constant: Numeric keypad Enter key. | |||||||||
int | KEYCODE_NUMPAD_EQUALS | Key code constant: Numeric keypad '=' key. | |||||||||
int | KEYCODE_NUMPAD_LEFT_PAREN | Key code constant: Numeric keypad '(' key. | |||||||||
int | KEYCODE_NUMPAD_MULTIPLY | Key code constant: Numeric keypad '*' key (for multiplication). | |||||||||
int | KEYCODE_NUMPAD_RIGHT_PAREN | Key code constant: Numeric keypad ')' key. | |||||||||
int | KEYCODE_NUMPAD_SUBTRACT | Key code constant: Numeric keypad '-' key (for subtraction). | |||||||||
int | KEYCODE_NUM_LOCK | Key code constant: Num Lock key. | |||||||||
int | KEYCODE_O | Key code constant: 'O' key. | |||||||||
int | KEYCODE_P | Key code constant: 'P' key. | |||||||||
int | KEYCODE_PAGE_DOWN | Key code constant: Page Down key. | |||||||||
int | KEYCODE_PAGE_UP | Key code constant: Page Up key. | |||||||||
int | KEYCODE_PERIOD | Key code constant: '.' key. | |||||||||
int | KEYCODE_PICTSYMBOLS | Key code constant: Picture Symbols modifier key. | |||||||||
int | KEYCODE_PLUS | Key code constant: '+' key. | |||||||||
int | KEYCODE_POUND | Key code constant: '#' key. | |||||||||
int | KEYCODE_POWER | Key code constant: Power key. | |||||||||
int | KEYCODE_PROG_BLUE | Key code constant: Blue "programmable" key. | |||||||||
int | KEYCODE_PROG_GREEN | Key code constant: Green "programmable" key. | |||||||||
int | KEYCODE_PROG_RED | Key code constant: Red "programmable" key. | |||||||||
int | KEYCODE_PROG_YELLOW | Key code constant: Yellow "programmable" key. | |||||||||
int | KEYCODE_Q | Key code constant: 'Q' key. | |||||||||
int | KEYCODE_R | Key code constant: 'R' key. | |||||||||
int | KEYCODE_RIGHT_BRACKET | Key code constant: ']' key. | |||||||||
int | KEYCODE_S | Key code constant: 'S' key. | |||||||||
int | KEYCODE_SCROLL_LOCK | Key code constant: Scroll Lock key. | |||||||||
int | KEYCODE_SEARCH | Key code constant: Search key. | |||||||||
int | KEYCODE_SEMICOLON | Key code constant: ';' key. | |||||||||
int | KEYCODE_SETTINGS | Key code constant: Settings key. | |||||||||
int | KEYCODE_SHIFT_LEFT | Key code constant: Left Shift modifier key. | |||||||||
int | KEYCODE_SHIFT_RIGHT | Key code constant: Right Shift modifier key. | |||||||||
int | KEYCODE_SLASH | Key code constant: '/' key. | |||||||||
int | KEYCODE_SOFT_LEFT | Key code constant: Soft Left key. | |||||||||
int | KEYCODE_SOFT_RIGHT | Key code constant: Soft Right key. | |||||||||
int | KEYCODE_SPACE | Key code constant: Space key. | |||||||||
int | KEYCODE_STAR | Key code constant: '*' key. | |||||||||
int | KEYCODE_STB_INPUT | Key code constant: Set-top-box input key. | |||||||||
int | KEYCODE_STB_POWER | Key code constant: Set-top-box power key. | |||||||||
int | KEYCODE_SWITCH_CHARSET | Key code constant: Switch Charset modifier key. | |||||||||
int | KEYCODE_SYM | Key code constant: Symbol modifier key. | |||||||||
int | KEYCODE_SYSRQ | Key code constant: System Request / Print Screen key. | |||||||||
int | KEYCODE_T | Key code constant: 'T' key. | |||||||||
int | KEYCODE_TAB | Key code constant: Tab key. | |||||||||
int | KEYCODE_TV | Key code constant: TV key. | |||||||||
int | KEYCODE_TV_INPUT | Key code constant: TV input key. | |||||||||
int | KEYCODE_TV_POWER | Key code constant: TV power key. | |||||||||
int | KEYCODE_U | Key code constant: 'U' key. | |||||||||
int | KEYCODE_UNKNOWN | Key code constant: Unknown key code. | |||||||||
int | KEYCODE_V | Key code constant: 'V' key. | |||||||||
int | KEYCODE_VOLUME_DOWN | Key code constant: Volume Down key. | |||||||||
int | KEYCODE_VOLUME_MUTE | Key code constant: Volume Mute key. | |||||||||
int | KEYCODE_VOLUME_UP | Key code constant: Volume Up key. | |||||||||
int | KEYCODE_W | Key code constant: 'W' key. | |||||||||
int | KEYCODE_WINDOW | Key code constant: Window key. | |||||||||
int | KEYCODE_X | Key code constant: 'X' key. | |||||||||
int | KEYCODE_Y | Key code constant: 'Y' key. | |||||||||
int | KEYCODE_Z | Key code constant: 'Z' key. | |||||||||
int | KEYCODE_ZOOM_IN | Key code constant: Zoom in key. | |||||||||
int | KEYCODE_ZOOM_OUT | Key code constant: Zoom out key. | |||||||||
int | MAX_KEYCODE | This constant is deprecated. There are now more than MAX_KEYCODE keycodes. Use getMaxKeyCode() instead. |
|||||||||
int | META_ALT_LEFT_ON | This mask is used to check whether the left ALT meta key is pressed. |
|||||||||
int | META_ALT_MASK | This mask is a combination of META_ALT_ON , META_ALT_LEFT_ON and META_ALT_RIGHT_ON . |
|||||||||
int | META_ALT_ON | This mask is used to check whether one of the ALT meta keys is pressed. |
|||||||||
int | META_ALT_RIGHT_ON | This mask is used to check whether the right the ALT meta key is pressed. |
|||||||||
int | META_CAPS_LOCK_ON | This mask is used to check whether the CAPS LOCK meta key is on. |
|||||||||
int | META_CTRL_LEFT_ON | This mask is used to check whether the left CTRL meta key is pressed. |
|||||||||
int | META_CTRL_MASK | This mask is a combination of META_CTRL_ON , META_CTRL_LEFT_ON and META_CTRL_RIGHT_ON . |
|||||||||
int | META_CTRL_ON | This mask is used to check whether one of the CTRL meta keys is pressed. |
|||||||||
int | META_CTRL_RIGHT_ON | This mask is used to check whether the right CTRL meta key is pressed. |
|||||||||
int | META_FUNCTION_ON | This mask is used to check whether the FUNCTION meta key is pressed. |
|||||||||
int | META_META_LEFT_ON | This mask is used to check whether the left META meta key is pressed. |
|||||||||
int | META_META_MASK | This mask is a combination of META_META_ON , META_META_LEFT_ON and META_META_RIGHT_ON . |
|||||||||
int | META_META_ON | This mask is used to check whether one of the META meta keys is pressed. |
|||||||||
int | META_META_RIGHT_ON | This mask is used to check whether the right META meta key is pressed. |
|||||||||
int | META_NUM_LOCK_ON | This mask is used to check whether the NUM LOCK meta key is on. |
|||||||||
int | META_SCROLL_LOCK_ON | This mask is used to check whether the SCROLL LOCK meta key is on. |
|||||||||
int | META_SHIFT_LEFT_ON | This mask is used to check whether the left SHIFT meta key is pressed. |
|||||||||
int | META_SHIFT_MASK | This mask is a combination of META_SHIFT_ON , META_SHIFT_LEFT_ON and META_SHIFT_RIGHT_ON . |
|||||||||
int | META_SHIFT_ON | This mask is used to check whether one of the SHIFT meta keys is pressed. |
|||||||||
int | META_SHIFT_RIGHT_ON | This mask is used to check whether the right SHIFT meta key is pressed. |
|||||||||
int | META_SYM_ON | This mask is used to check whether the SYM meta key is pressed. |