Android自动化工具Monkeyrunner使用(五)

     本章开始介绍下MonkeyrunnerAPI, 以便了解其具体的使用。

void press (string name, dictionary type) : 可以说是对键盘的操作

Sends the key event specified by type to the key specified by keycode. 


void press (string name, integer type)

Sends the key event specified by type to the key specified by keycode.

Arguments
nameThe name of the keycode to send. See KeyEvent for a list of keycode names. Use the keycode name, not its integer value.
typeThe 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
intACTION_DOWNgetAction() value: the key has been pressed down.
intACTION_MULTIPLEgetAction() value: multiple duplicate key events have occurred in a row, or a complex string is being delivered.
intACTION_UPgetAction() value: the key has been released.
intFLAG_CANCELEDWhen associated with up key events, this indicates that the key press has been canceled.
intFLAG_CANCELED_LONG_PRESSSet when a key event has FLAG_CANCELED set because a long press action was executed while it was down.
intFLAG_EDITOR_ACTIONThis 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".
intFLAG_FALLBACKSet when a key event has been synthesized to implement default behavior for an event that the application did not handle.
intFLAG_FROM_SYSTEMThis mask is set if an event was known to come from a trusted part of the system.
intFLAG_KEEP_TOUCH_MODEThis mask is set if we don't want the key event to cause us to leave touch mode.
intFLAG_LONG_PRESSThis flag is set for the first key repeat that occurs after the long press timeout.
intFLAG_SOFT_KEYBOARDThis mask is set if the key event was generated by a software keyboard.
intFLAG_TRACKINGSet for ACTION_UP when this event's key code is still being tracked from its initial down.
intFLAG_VIRTUAL_HARD_KEYThis key event was generated by a virtual (on-screen) hard key area.
intFLAG_WOKE_HEREThis mask is set if the device woke because of this key event.
intKEYCODE_0Key code constant: '0' key.
intKEYCODE_1Key code constant: '1' key.
intKEYCODE_2Key code constant: '2' key.
intKEYCODE_3Key code constant: '3' key.
intKEYCODE_3D_MODEKey code constant: 3D Mode key.
intKEYCODE_4Key code constant: '4' key.
intKEYCODE_5Key code constant: '5' key.
intKEYCODE_6Key code constant: '6' key.
intKEYCODE_7Key code constant: '7' key.
intKEYCODE_8Key code constant: '8' key.
intKEYCODE_9Key code constant: '9' key.
intKEYCODE_AKey code constant: 'A' key.
intKEYCODE_ALT_LEFTKey code constant: Left Alt modifier key.
intKEYCODE_ALT_RIGHTKey code constant: Right Alt modifier key.
intKEYCODE_APOSTROPHEKey code constant: ''' (apostrophe) key.
intKEYCODE_APP_SWITCHKey code constant: App switch key.
intKEYCODE_ATKey code constant: '@' key.
intKEYCODE_AVR_INPUTKey code constant: A/V Receiver input key.
intKEYCODE_AVR_POWERKey code constant: A/V Receiver power key.
intKEYCODE_BKey code constant: 'B' key.
intKEYCODE_BACKKey code constant: Back key.
intKEYCODE_BACKSLASHKey code constant: '\' key.
intKEYCODE_BOOKMARKKey code constant: Bookmark key.
intKEYCODE_BREAKKey code constant: Break / Pause key.
intKEYCODE_BUTTON_1Key code constant: Generic Game Pad Button #1.
intKEYCODE_BUTTON_10Key code constant: Generic Game Pad Button #10.
intKEYCODE_BUTTON_11Key code constant: Generic Game Pad Button #11.
intKEYCODE_BUTTON_12Key code constant: Generic Game Pad Button #12.
intKEYCODE_BUTTON_13Key code constant: Generic Game Pad Button #13.
intKEYCODE_BUTTON_14Key code constant: Generic Game Pad Button #14.
intKEYCODE_BUTTON_15Key code constant: Generic Game Pad Button #15.
intKEYCODE_BUTTON_16Key code constant: Generic Game Pad Button #16.
intKEYCODE_BUTTON_2Key code constant: Generic Game Pad Button #2.
intKEYCODE_BUTTON_3Key code constant: Generic Game Pad Button #3.
intKEYCODE_BUTTON_4Key code constant: Generic Game Pad Button #4.
intKEYCODE_BUTTON_5Key code constant: Generic Game Pad Button #5.
intKEYCODE_BUTTON_6Key code constant: Generic Game Pad Button #6.
intKEYCODE_BUTTON_7Key code constant: Generic Game Pad Button #7.
intKEYCODE_BUTTON_8Key code constant: Generic Game Pad Button #8.
intKEYCODE_BUTTON_9Key code constant: Generic Game Pad Button #9.
intKEYCODE_BUTTON_AKey code constant: A Button key.
intKEYCODE_BUTTON_BKey code constant: B Button key.
intKEYCODE_BUTTON_CKey code constant: C Button key.
intKEYCODE_BUTTON_L1Key code constant: L1 Button key.
intKEYCODE_BUTTON_L2Key code constant: L2 Button key.
intKEYCODE_BUTTON_MODEKey code constant: Mode Button key.
intKEYCODE_BUTTON_R1Key code constant: R1 Button key.
intKEYCODE_BUTTON_R2Key code constant: R2 Button key.
intKEYCODE_BUTTON_SELECTKey code constant: Select Button key.
intKEYCODE_BUTTON_STARTKey code constant: Start Button key.
intKEYCODE_BUTTON_THUMBLKey code constant: Left Thumb Button key.
intKEYCODE_BUTTON_THUMBRKey code constant: Right Thumb Button key.
intKEYCODE_BUTTON_XKey code constant: X Button key.
intKEYCODE_BUTTON_YKey code constant: Y Button key.
intKEYCODE_BUTTON_ZKey code constant: Z Button key.
intKEYCODE_CKey code constant: 'C' key.
intKEYCODE_CALCULATORKey code constant: Calculator special function key.
intKEYCODE_CALENDARKey code constant: Calendar special function key.
intKEYCODE_CALLKey code constant: Call key.
intKEYCODE_CAMERAKey code constant: Camera key.
intKEYCODE_CAPS_LOCKKey code constant: Caps Lock key.
intKEYCODE_CAPTIONSKey code constant: Toggle captions key.
intKEYCODE_CHANNEL_DOWNKey code constant: Channel down key.
intKEYCODE_CHANNEL_UPKey code constant: Channel up key.
intKEYCODE_CLEARKey code constant: Clear key.
intKEYCODE_COMMAKey code constant: ',' key.
intKEYCODE_CONTACTSKey code constant: Contacts special function key.
intKEYCODE_CTRL_LEFTKey code constant: Left Control modifier key.
intKEYCODE_CTRL_RIGHTKey code constant: Right Control modifier key.
intKEYCODE_DKey code constant: 'D' key.
intKEYCODE_DELKey code constant: Backspace key.
intKEYCODE_DPAD_CENTERKey code constant: Directional Pad Center key.
intKEYCODE_DPAD_DOWNKey code constant: Directional Pad Down key.
intKEYCODE_DPAD_LEFTKey code constant: Directional Pad Left key.
intKEYCODE_DPAD_RIGHTKey code constant: Directional Pad Right key.
intKEYCODE_DPAD_UPKey code constant: Directional Pad Up key.
intKEYCODE_DVRKey code constant: DVR key.
intKEYCODE_EKey code constant: 'E' key.
intKEYCODE_ENDCALLKey code constant: End Call key.
intKEYCODE_ENTERKey code constant: Enter key.
intKEYCODE_ENVELOPEKey code constant: Envelope special function key.
intKEYCODE_EQUALSKey code constant: '=' key.
intKEYCODE_ESCAPEKey code constant: Escape key.
intKEYCODE_EXPLORERKey code constant: Explorer special function key.
intKEYCODE_FKey code constant: 'F' key.
intKEYCODE_F1Key code constant: F1 key.
intKEYCODE_F10Key code constant: F10 key.
intKEYCODE_F11Key code constant: F11 key.
intKEYCODE_F12Key code constant: F12 key.
intKEYCODE_F2Key code constant: F2 key.
intKEYCODE_F3Key code constant: F3 key.
intKEYCODE_F4Key code constant: F4 key.
intKEYCODE_F5Key code constant: F5 key.
intKEYCODE_F6Key code constant: F6 key.
intKEYCODE_F7Key code constant: F7 key.
intKEYCODE_F8Key code constant: F8 key.
intKEYCODE_F9Key code constant: F9 key.
intKEYCODE_FOCUSKey code constant: Camera Focus key.
intKEYCODE_FORWARDKey code constant: Forward key.
intKEYCODE_FORWARD_DELKey code constant: Forward Delete key.
intKEYCODE_FUNCTIONKey code constant: Function modifier key.
intKEYCODE_GKey code constant: 'G' key.
intKEYCODE_GRAVEKey code constant: '`' (backtick) key.
intKEYCODE_GUIDEKey code constant: Guide key.
intKEYCODE_HKey code constant: 'H' key.
intKEYCODE_HEADSETHOOKKey code constant: Headset Hook key.
intKEYCODE_HOMEKey code constant: Home key.
intKEYCODE_IKey code constant: 'I' key.
intKEYCODE_INFOKey code constant: Info key.
intKEYCODE_INSERTKey code constant: Insert key.
intKEYCODE_JKey code constant: 'J' key.
intKEYCODE_KKey code constant: 'K' key.
intKEYCODE_LKey code constant: 'L' key.
intKEYCODE_LANGUAGE_SWITCHKey code constant: Language Switch key.
intKEYCODE_LEFT_BRACKETKey code constant: '[' key.
intKEYCODE_MKey code constant: 'M' key.
intKEYCODE_MANNER_MODEKey code constant: Manner Mode key.
intKEYCODE_MEDIA_CLOSEKey code constant: Close media key.
intKEYCODE_MEDIA_EJECTKey code constant: Eject media key.
intKEYCODE_MEDIA_FAST_FORWARDKey code constant: Fast Forward media key.
intKEYCODE_MEDIA_NEXTKey code constant: Play Next media key.
intKEYCODE_MEDIA_PAUSEKey code constant: Pause media key.
intKEYCODE_MEDIA_PLAYKey code constant: Play media key.
intKEYCODE_MEDIA_PLAY_PAUSEKey code constant: Play/Pause media key.
intKEYCODE_MEDIA_PREVIOUSKey code constant: Play Previous media key.
intKEYCODE_MEDIA_RECORDKey code constant: Record media key.
intKEYCODE_MEDIA_REWINDKey code constant: Rewind media key.
intKEYCODE_MEDIA_STOPKey code constant: Stop media key.
intKEYCODE_MENUKey code constant: Menu key.
intKEYCODE_META_LEFTKey code constant: Left Meta modifier key.
intKEYCODE_META_RIGHTKey code constant: Right Meta modifier key.
intKEYCODE_MINUSKey code constant: '-'.
intKEYCODE_MOVE_ENDKey code constant: End Movement key.
intKEYCODE_MOVE_HOMEKey code constant: Home Movement key.
intKEYCODE_MUSICKey code constant: Music special function key.
intKEYCODE_MUTEKey code constant: Mute key.
intKEYCODE_NKey code constant: 'N' key.
intKEYCODE_NOTIFICATIONKey code constant: Notification key.
intKEYCODE_NUMKey code constant: Number modifier key.
intKEYCODE_NUMPAD_0Key code constant: Numeric keypad '0' key.
intKEYCODE_NUMPAD_1Key code constant: Numeric keypad '1' key.
intKEYCODE_NUMPAD_2Key code constant: Numeric keypad '2' key.
intKEYCODE_NUMPAD_3Key code constant: Numeric keypad '3' key.
intKEYCODE_NUMPAD_4Key code constant: Numeric keypad '4' key.
intKEYCODE_NUMPAD_5Key code constant: Numeric keypad '5' key.
intKEYCODE_NUMPAD_6Key code constant: Numeric keypad '6' key.
intKEYCODE_NUMPAD_7Key code constant: Numeric keypad '7' key.
intKEYCODE_NUMPAD_8Key code constant: Numeric keypad '8' key.
intKEYCODE_NUMPAD_9Key code constant: Numeric keypad '9' key.
intKEYCODE_NUMPAD_ADDKey code constant: Numeric keypad '+' key (for addition).
intKEYCODE_NUMPAD_COMMAKey code constant: Numeric keypad ',' key (for decimals or digit grouping).
intKEYCODE_NUMPAD_DIVIDEKey code constant: Numeric keypad '/' key (for division).
intKEYCODE_NUMPAD_DOTKey code constant: Numeric keypad '.' key (for decimals or digit grouping).
intKEYCODE_NUMPAD_ENTERKey code constant: Numeric keypad Enter key.
intKEYCODE_NUMPAD_EQUALSKey code constant: Numeric keypad '=' key.
intKEYCODE_NUMPAD_LEFT_PARENKey code constant: Numeric keypad '(' key.
intKEYCODE_NUMPAD_MULTIPLYKey code constant: Numeric keypad '*' key (for multiplication).
intKEYCODE_NUMPAD_RIGHT_PARENKey code constant: Numeric keypad ')' key.
intKEYCODE_NUMPAD_SUBTRACTKey code constant: Numeric keypad '-' key (for subtraction).
intKEYCODE_NUM_LOCKKey code constant: Num Lock key.
intKEYCODE_OKey code constant: 'O' key.
intKEYCODE_PKey code constant: 'P' key.
intKEYCODE_PAGE_DOWNKey code constant: Page Down key.
intKEYCODE_PAGE_UPKey code constant: Page Up key.
intKEYCODE_PERIODKey code constant: '.' key.
intKEYCODE_PICTSYMBOLSKey code constant: Picture Symbols modifier key.
intKEYCODE_PLUSKey code constant: '+' key.
intKEYCODE_POUNDKey code constant: '#' key.
intKEYCODE_POWERKey code constant: Power key.
intKEYCODE_PROG_BLUEKey code constant: Blue "programmable" key.
intKEYCODE_PROG_GREENKey code constant: Green "programmable" key.
intKEYCODE_PROG_REDKey code constant: Red "programmable" key.
intKEYCODE_PROG_YELLOWKey code constant: Yellow "programmable" key.
intKEYCODE_QKey code constant: 'Q' key.
intKEYCODE_RKey code constant: 'R' key.
intKEYCODE_RIGHT_BRACKETKey code constant: ']' key.
intKEYCODE_SKey code constant: 'S' key.
intKEYCODE_SCROLL_LOCKKey code constant: Scroll Lock key.
intKEYCODE_SEARCHKey code constant: Search key.
intKEYCODE_SEMICOLONKey code constant: ';' key.
intKEYCODE_SETTINGSKey code constant: Settings key.
intKEYCODE_SHIFT_LEFTKey code constant: Left Shift modifier key.
intKEYCODE_SHIFT_RIGHTKey code constant: Right Shift modifier key.
intKEYCODE_SLASHKey code constant: '/' key.
intKEYCODE_SOFT_LEFTKey code constant: Soft Left key.
intKEYCODE_SOFT_RIGHTKey code constant: Soft Right key.
intKEYCODE_SPACEKey code constant: Space key.
intKEYCODE_STARKey code constant: '*' key.
intKEYCODE_STB_INPUTKey code constant: Set-top-box input key.
intKEYCODE_STB_POWERKey code constant: Set-top-box power key.
intKEYCODE_SWITCH_CHARSETKey code constant: Switch Charset modifier key.
intKEYCODE_SYMKey code constant: Symbol modifier key.
intKEYCODE_SYSRQKey code constant: System Request / Print Screen key.
intKEYCODE_TKey code constant: 'T' key.
intKEYCODE_TABKey code constant: Tab key.
intKEYCODE_TVKey code constant: TV key.
intKEYCODE_TV_INPUTKey code constant: TV input key.
intKEYCODE_TV_POWERKey code constant: TV power key.
intKEYCODE_UKey code constant: 'U' key.
intKEYCODE_UNKNOWNKey code constant: Unknown key code.
intKEYCODE_VKey code constant: 'V' key.
intKEYCODE_VOLUME_DOWNKey code constant: Volume Down key.
intKEYCODE_VOLUME_MUTEKey code constant: Volume Mute key.
intKEYCODE_VOLUME_UPKey code constant: Volume Up key.
intKEYCODE_WKey code constant: 'W' key.
intKEYCODE_WINDOWKey code constant: Window key.
intKEYCODE_XKey code constant: 'X' key.
intKEYCODE_YKey code constant: 'Y' key.
intKEYCODE_ZKey code constant: 'Z' key.
intKEYCODE_ZOOM_INKey code constant: Zoom in key.
intKEYCODE_ZOOM_OUTKey code constant: Zoom out key.
intMAX_KEYCODEThis constant is deprecated. There are now more than MAX_KEYCODE keycodes. Use getMaxKeyCode() instead.
intMETA_ALT_LEFT_ON

This mask is used to check whether the left ALT meta key is pressed.

intMETA_ALT_MASKThis mask is a combination of META_ALT_ON, META_ALT_LEFT_ON and META_ALT_RIGHT_ON.
intMETA_ALT_ON

This mask is used to check whether one of the ALT meta keys is pressed.

intMETA_ALT_RIGHT_ON

This mask is used to check whether the right the ALT meta key is pressed.

intMETA_CAPS_LOCK_ON

This mask is used to check whether the CAPS LOCK meta key is on.

intMETA_CTRL_LEFT_ON

This mask is used to check whether the left CTRL meta key is pressed.

intMETA_CTRL_MASKThis mask is a combination of META_CTRL_ON, META_CTRL_LEFT_ON and META_CTRL_RIGHT_ON.
intMETA_CTRL_ON

This mask is used to check whether one of the CTRL meta keys is pressed.

intMETA_CTRL_RIGHT_ON

This mask is used to check whether the right CTRL meta key is pressed.

intMETA_FUNCTION_ON

This mask is used to check whether the FUNCTION meta key is pressed.

intMETA_META_LEFT_ON

This mask is used to check whether the left META meta key is pressed.

intMETA_META_MASKThis mask is a combination of META_META_ON, META_META_LEFT_ON and META_META_RIGHT_ON.
intMETA_META_ON

This mask is used to check whether one of the META meta keys is pressed.

intMETA_META_RIGHT_ON

This mask is used to check whether the right META meta key is pressed.

intMETA_NUM_LOCK_ON

This mask is used to check whether the NUM LOCK meta key is on.

intMETA_SCROLL_LOCK_ON

This mask is used to check whether the SCROLL LOCK meta key is on.

intMETA_SHIFT_LEFT_ON

This mask is used to check whether the left SHIFT meta key is pressed.

intMETA_SHIFT_MASKThis mask is a combination of META_SHIFT_ON, META_SHIFT_LEFT_ON and META_SHIFT_RIGHT_ON.
intMETA_SHIFT_ON

This mask is used to check whether one of the SHIFT meta keys is pressed.

intMETA_SHIFT_RIGHT_ON

This mask is used to check whether the right SHIFT meta key is pressed.

intMETA_SYM_ON

This mask is used to check whether the SYM meta key is pressed.


  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值