上一版的实现:https://testerhome.com/topics/7785 中暴露了许多问题,尤其是方案不统一的做法非常不好,经过 Macaca 开发小组讨论,按照各端统一的做法来实现了 keys。
首先还是升级驱动版本到最新,然后使用 Macaca 提供的 Node.js Java 或 Python 语言包,调用keys
即可,例如:
const KEY_MAP = require('webdriver-keycode');
driver.keys(`send keys: ${KEY_MAP.HOME_SCREEN}`) // 输入“send keys: ”字符后会按HOME_SCREEN
更多参考文档请见:https://github.com/alibaba/macaca/issues/487,此文档会随着功能实现同步更新
\uE002
"HELP" => 259 (0x00000103)
\uE003
"BACK_SPACE" => 67 (0x00000043)
\uE004
"TAB" => 61 (0x0000003d)
\uE005
"CLEAR" => 28 (0x0000001c)
\uE007
"ENTER" => 66 (0x00000042)
\uE008
"SHIFT" => 59 (0x0000003b)
\uE009
"CONTROL" => 113 (0x00000071)
\uE00A
"ALT" => 57 (0x00000039)
\uE00B
"PAUSE" => 121 (0x00000079)
\uE00C
"ESCAPE" => 111 (0x0000006f)
\uE00E
"PAGE_UP" => 92 (0x0000005c)
\uE00F
"PAGE_DOWN" => 93 (0x0000005d)
\uE010
"END" => 123 (0x0000007b)
\uE011
"HOME" => 122 (0x0000007a)
\uE012
"ARROW_LEFT" => 21 (0x00000015)
\uE013
"ARROW_UP" => 19 (0x00000013)
\uE014
"ARROW_RIGHT" => 22 (0x00000016)
\uE015
"ARROW_DOWN" => 20 (0x00000014)
\uE016
"INSERT" => 124 (0x0000007c)
\uE017
"DELETE" => 112 (0x00000070)
\uE031
"F1" => 131 (0x00000083)
\uE032
"F2" => 132 (0x00000084)
\uE033
"F3" => 133 (0x00000085)
\uE034
"F4" => 134 (0x00000086)
\uE035
"F5" => 135 (0x00000087)
\uE036
"F6" => 136 (0x00000088)
\uE037
"F7" => 137 (0x00000089)
\uE038
"F8" => 138 (0x0000008a)
\uE039
"F9" => 139 (0x0000008b)
\uE03A
"F10" => 140 (0x0000008c)
\uE03B
"F11" => 141 (0x0000008d)
\uE03C
"F12" => 142 (0x0000008e)
\uE03D
"META" => 117 (0x00000075)
\uE101
"POWER 电源键" => 26 (0x0000001a)
\uE102
"VOLUME_UP 音量加" => 24 (0x00000018)
\uE103
"VOLUME_DOWN 音量减" => 25 (0x00000019)
\uE104
"VOLUME_MUTE 禁音" => 164 (0x000000a4)
\uE105
"HOME_SCREEN HOME 键" => 3 (0x00000003)
\uE106
"BACK BACK 键" => 4 (0x00000004)
\uE107
"MENU MENU 键" => 82 (0x00000052)
\uE108
"CAMERA 拍照键" => 27 (0x0000001b)
\uE109
"CALL 电话键" => 5 (0x00000005)
\uE10A
"END_CALL 结束电话键" => 6 (0x00000006)
\uE10B
"SEARCH 搜索键" => 84 (0x00000054)
\uE10C
"DPAD_LEFT 导航左键" => 21 (0x00000015)
\uE10D
"DPAD_UP 导航上键" => 19 (0x00000013)
\uE10E
"DPAD_RIGHT 导航右键" => 22 (0x00000016)
\uE10F
"DPAD_DOWN 导航下键" => 20 (0x00000014)
\uE110
"DPAD_CENTER 导航确定键" => 23 (0x00000017)
\uE105
"HOME_SCREEN HOME 键"