Appium Android keycode 列表 (稍全)

Alex · September 12, 2014 · Last by Alex replied at September 19, 2016 · 4456 hits
本帖已被设为精华帖!

信息来源:http://developer.android.com/reference/android/view/KeyEvent.html

KEYCODE_0      '0' key.   7
KEYCODE_1 '1' key. 8
KEYCODE_2 '2' key. 9
KEYCODE_3 '3' key. 10
KEYCODE_4 '4' key. 11
KEYCODE_5 '5' key. 12
KEYCODE_6 '6' key. 13
KEYCODE_7 '7' key. 14
KEYCODE_8 '8' key. 15
KEYCODE_9 '9' key. 16

KEYCODE_A 'A' key. 29
KEYCODE_B 'B' key. 30
KEYCODE_C 'C' key. 31
KEYCODE_D 'D' key. 32
KEYCODE_E 'E' key. 33
KEYCODE_F 'F' key. 34
KEYCODE_G 'G' key. 35
KEYCODE_H 'H' key. 36
KEYCODE_I 'I' key. 37
KEYCODE_J 'J' key. 38
KEYCODE_K 'K' key. 39
KEYCODE_L 'L' key. 40
KEYCODE_M 'M' key. 41
KEYCODE_N 'N' key. 42
KEYCODE_O 'O' key. 43
KEYCODE_P 'P' key. 44
KEYCODE_Q 'Q' key. 45
KEYCODE_R 'R' key. 46
KEYCODE_S 'S' key. 47
KEYCODE_T 'T' key. 48
KEYCODE_U 'U' key. 49
KEYCODE_V 'V' key. 50
KEYCODE_W 'W' key. 51
KEYCODE_X 'X' key. 52
KEYCODE_Y 'Y' key. 53
KEYCODE_Z 'Z' key. 54

META_ALT_LEFT_ON This mask is used to check whether the left ALT meta key is pressed. 16
META_ALT_MASK This mask is a combination of META_ALT_ON, META_ALT_LEFT_ON and META_ALT_RIGHT_ON. 50
META_ALT_ON This mask is used to check whether one of the ALT meta keys is pressed. 2
META_ALT_RIGHT_ON This mask is used to check whether the right the ALT meta key is pressed. 32
META_CAPS_LOCK_ON This mask is used to check whether the CAPS LOCK meta key is on. 1048576
META_CTRL_LEFT_ON This mask is used to check whether the left CTRL meta key is pressed. 8192
META_CTRL_MASK This mask is a combination of META_CTRL_ON, META_CTRL_LEFT_ON and META_CTRL_RIGHT_ON. 28672
META_CTRL_ON This mask is used to check whether one of the CTRL meta keys is pressed. 4096
META_CTRL_RIGHT_ON This mask is used to check whether the right CTRL meta key is pressed. 16384
META_FUNCTION_ON This mask is used to check whether the FUNCTION meta key is pressed. 8
META_META_LEFT_ON This mask is used to check whether the left META meta key is pressed. 131072
META_META_MASK This mask is a combination of META_META_ON, META_META_LEFT_ON and META_META_RIGHT_ON. 458752
META_META_ON This mask is used to check whether one of the META meta keys is pressed. 65536
META_META_RIGHT_ON This mask is used to check whether the right META meta key is pressed. 262144
META_NUM_LOCK_ON This mask is used to check whether the NUM LOCK meta key is on. 2097152
META_SCROLL_LOCK_ON This mask is used to check whether the SCROLL LOCK meta key is on. 4194304
META_SHIFT_LEFT_ON This mask is used to check whether the left SHIFT meta key is pressed. 64
META_SHIFT_MASK This mask is a combination of META_SHIFT_ON, META_SHIFT_LEFT_ON and META_SHIFT_RIGHT_ON. 193
META_SHIFT_ON This mask is used to check whether one of the SHIFT meta keys is pressed. 1
META_SHIFT_RIGHT_ON This mask is used to check whether the right SHIFT meta key is pressed. 128
META_SYM_ON This mask is used to check whether the SYM meta key is pressed. 4

KEYCODE_APOSTROPHE ''' key. 75
KEYCODE_AT '@' key. 77
KEYCODE_BACKSLASH '\' key. 73
KEYCODE_COMMA ',' key. 55
KEYCODE_EQUALS '=' key. 70
KEYCODE_GRAVE '`' key. 68
KEYCODE_LEFT_BRACKET '[' key. 71
KEYCODE_MINUS '-' key. 69
KEYCODE_PERIOD '.' key. 56
KEYCODE_PLUS '+' key. 81
KEYCODE_POUND '#' key. 18
KEYCODE_RIGHT_BRACKET ']' key. 72
KEYCODE_SEMICOLON ';' key. 74
KEYCODE_SLASH '/' key. 76
KEYCODE_STAR '*' key. 17
KEYCODE_SPACE Space key. 62
KEYCODE_TAB Tab key. 61

KEYCODE_ENTER Enter key. 66
KEYCODE_ESCAPE Escape key. 111
KEYCODE_CAPS_LOCK Caps Lock key. 115
KEYCODE_CLEAR Clear key. 28
KEYCODE_PAGE_DOWN Page Down key. 93
KEYCODE_PAGE_UP Page Up key. 92
KEYCODE_SCROLL_LOCK Scroll Lock key. 116
KEYCODE_MOVE_END End. 123
KEYCODE_MOVE_HOME Home. 122
KEYCODE_INSERT Insert key. 124
KEYCODE_SHIFT_LEFT Left Shift. 59
KEYCODE_SHIFT_RIGHT Right Shift. 60

KEYCODE_F1 F1 key. 131
KEYCODE_F2 F2 key. 132
KEYCODE_F3 F3 key. 133
KEYCODE_F4 F4 key. 134
KEYCODE_F5 F5 key. 135
KEYCODE_F6 F6 key. 136
KEYCODE_F7 F7 key. 137
KEYCODE_F8 F8 key. 138
KEYCODE_F9 F9 key. 139
KEYCODE_F10 F10 key. 140
KEYCODE_F11 F11 key. 141
KEYCODE_F12 F12 key. 142

KEYCODE_BACK Back key. 4
KEYCODE_CALL Call key. 5
KEYCODE_ENDCALL End Call key. 6
KEYCODE_CAMERA Camera key. 27
KEYCODE_FOCUS Camera Focus key. 80
KEYCODE_VOLUME_UP Volume Up key. 24
KEYCODE_VOLUME_DOWN Volume Down key. 25
KEYCODE_VOLUME_MUTE Volume Mute key. 164
KEYCODE_MENU Menu key. 82
KEYCODE_HOME Home key. 3
KEYCODE_POWER Power key. 26
KEYCODE_SEARCH Search key. 84
KEYCODE_NOTIFICATION Notification key. 83
KEYCODE_NUM Number modifier key. 78
KEYCODE_SYM Symbol modifier key. 63
KEYCODE_SETTINGS Settings key. 176

KEYCODE_DEL Backspace key. Deletes characters before the insertion point, unlike KEYCODE_FORWARD_DEL. 67
KEYCODE_FORWARD_DEL Forward Delete key. Deletes characters ahead of the insertion point, unlike KEYCODE_DEL. 112

KEYCODE_NUMPAD_0 Numeric keypad '0' key. 144
KEYCODE_NUMPAD_1 Numeric keypad '1' key. 145
KEYCODE_NUMPAD_2 Numeric keypad '2' key. 146
KEYCODE_NUMPAD_3 Numeric keypad '3' key. 147
KEYCODE_NUMPAD_4 Numeric keypad '4' key. 148
KEYCODE_NUMPAD_5 Numeric keypad '5' key. 149
KEYCODE_NUMPAD_6 Numeric keypad '6' key. 150
KEYCODE_NUMPAD_7 Numeric keypad '7' key. 151
KEYCODE_NUMPAD_8 Numeric keypad '8' key. 152
KEYCODE_NUMPAD_9 Numeric keypad '9' key. 153
KEYCODE_NUMPAD_ADD Numeric keypad '+' key 157
KEYCODE_NUMPAD_COMMA Numeric keypad ',' key 159
KEYCODE_NUMPAD_DIVIDE Numeric keypad '/' key 154
KEYCODE_NUMPAD_DOT Numeric keypad '.' key 158
KEYCODE_NUMPAD_EQUALS Numeric keypad '=' key. 161
KEYCODE_NUMPAD_LEFT_PAREN Numeric keypad '(' key. 162
KEYCODE_NUMPAD_MULTIPLY Numeric keypad '*' key 155
KEYCODE_NUMPAD_RIGHT_PAREN Numeric keypad ')' key. 163
KEYCODE_NUMPAD_SUBTRACT Numeric keypad '-' key 156
KEYCODE_NUMPAD_ENTER Numeric keypad Enter key. 160
KEYCODE_NUM_LOCK Numeric keypad Num Lock key. 143


KEYCODE_MEDIA_FAST_FORWARD Fast Forward media key. 90
KEYCODE_MEDIA_NEXT Play Next media key. 87
KEYCODE_MEDIA_PAUSE Pause media key. 127
KEYCODE_MEDIA_PLAY Play media key. 126
KEYCODE_MEDIA_PLAY_PAUSE Play/Pause media key. 85
KEYCODE_MEDIA_PREVIOUS Play Previous media key. 88
KEYCODE_MEDIA_RECORD Record media key. 130
KEYCODE_MEDIA_REWIND Rewind media key. 89
KEYCODE_MEDIA_STOP Stop media key. 86
共收到 13 条回复 时间 点赞

可以简单介绍下 如何使用吧

iOS能用不?

对于IOS能否使用,因为我这没有IOS的环境,所以不能确定,我觉得能用的可能性很大,因为我有在pc的web上试过,大多数常用的key都是没问题的。

对于用法,在Appium中,有内置的方法 def press_keycode(self, keycode, metastate=None), 这是python的,其他语言类似.

它有两个参数,keycode, metastate

如果只输入普通字符(abc,123等),直接press_keycode(29), 29代表‘a’,其他keycode可以在上面的列表中查到。

如果要输入组合键,比如大写‘A’,或者ctrl+c等,要指定第二个参数,举个栗子:输入大写‘A’,实际上是shift+a,press_code(29, 193). 想全选要输入ctrl+a,press_keycode(29, 28672). 组合键的关键在于这几个键的应用:META_ALT_MASK,META_CTRL_MASK, META_SHIFT_MASK

当然press_keycode还可以实现手机上的Home,Back key等,press_keycode(3), press_keycode(4)

很全面,谢谢分享。

#2楼 @link1220 这是android的keycode。。 看看代码的来历啊。。

不错, 我记得cafe里面有个代码会通过反射方式读取KeyEvent类获得所有的key和code的对应关系

8Floor has been deleted

http://blog.sina.com.cn/s/blog_4cd5d2bb0101ggt6.html
这个博客里的可能更全一点。
其实好多都用不上。

直接调用sdk的keyevent类, 可以直接转换. 最常见的其实是ctrl alt之类的 可以记住

赞 赞,终于可以复制了,可是在华为手机上不太好使,我再看看 谢谢楼主分享这么多

为什么没有问号?还有感叹号!

需要 Sign In 后方可回复, 如果你还没有账号请点击这里 Sign Up