keys
This module provides global functions to simulate physical key presses, including Home, volume keys, camera key, etc. Some functions require the accessibility service, while others require root.
In general, functions whose names start with an uppercase letter require root. If root is not available, calling them will have no effect and a warning will be printed to the console.
back()
- Returns {boolean}
Simulates pressing the Back key. Returns whether the action was performed successfully. This function requires the accessibility service.
home()
- Returns {boolean}
Simulates pressing the Home key. Returns whether the action was performed successfully. This function requires the accessibility service.
powerDialog()
- Returns {boolean}
Shows the power menu. Returns whether the action was performed successfully. This function requires the accessibility service.
notifications()
- Returns {boolean}
Pulls down the notification shade. Returns whether the action was performed successfully. This function requires the accessibility service.
quickSettings()
- Returns {boolean}
Shows Quick Settings (pulls the notification shade all the way down). Returns whether the action was performed successfully. This function requires the accessibility service.
recents()
- Returns {boolean}
Shows recent apps. Returns whether the action was performed successfully. This function requires the accessibility service.
splitScreen()
- Returns {boolean}
Enters split-screen mode. Returns whether the action was performed successfully. This function requires the accessibility service and system support.
Home()
Simulates pressing the Home key. Requires root.
Back()
Simulates pressing the Back key. Requires root.
Power()
Simulates pressing the Power key. Requires root.
Menu()
Simulates pressing the Menu key. Requires root.
VolumeUp()
Presses Volume Up. Requires root.
VolumeDown()
Presses Volume Down. Requires root.
Camera()
Simulates pressing the camera key.
Up()
Simulates pressing the physical Up key. Requires root.
Down()
Simulates pressing the physical Down key. Requires root.
Left()
Simulates pressing the physical Left key. Requires root.
Right()
Simulates pressing the physical Right key. Requires root.
OK()
Simulates pressing the physical OK/Enter key. Requires root.
Text(text)
text{string} Text to input (English letters / symbols only). Example:Text("aaa");
KeyCode(code)
code{number} | {string} Numeric key code or key name (see table below). Simulates a physical key press. For example,KeyCode(29)andKeyCode("KEYCODE_A")press the A key.
Appendix: KeyCode table
| KeyCode | KeyEvent value |
|---|---|
| KEYCODE_MENU | 1 |
| KEYCODE_SOFT_RIGHT | 2 |
| KEYCODE_HOME | 3 |
| KEYCODE_BACK | 4 |
| KEYCODE_CALL | 5 |
| KEYCODE_ENDCALL | 6 |
| KEYCODE_0 | 7 |
| KEYCODE_1 | 8 |
| KEYCODE_2 | 9 |
| KEYCODE_3 | 10 |
| KEYCODE_4 | 11 |
| KEYCODE_5 | 12 |
| KEYCODE_6 | 13 |
| KEYCODE_7 | 14 |
| KEYCODE_8 | 15 |
| KEYCODE_9 | 16 |
| KEYCODE_STAR | 17 |
| KEYCODE_POUND | 18 |
| KEYCODE_DPAD_UP | 19 |
| KEYCODE_DPAD_DOWN | 20 |
| KEYCODE_DPAD_LEFT | 21 |
| KEYCODE_DPAD_RIGHT | 22 |
| KEYCODE_DPAD_CENTER | 23 |
| KEYCODE_VOLUME_UP | 24 |
| KEYCODE_VOLUME_DOWN | 25 |
| KEYCODE_POWER | 26 |
| KEYCODE_CAMERA | 27 |
| KEYCODE_CLEAR | 28 |
| KEYCODE_A | 29 |
| KEYCODE_B | 30 |
| KEYCODE_C | 31 |
| KEYCODE_D | 32 |
| KEYCODE_E | 33 |
| KEYCODE_F | 34 |
| KEYCODE_G | 35 |
| KEYCODE_H | 36 |
| KEYCODE_I | 37 |
| KEYCODE_J | 38 |
| KEYCODE_K | 39 |
| KEYCODE_L | 40 |
| KEYCODE_M | 41 |
| KEYCODE_N | 42 |
| KEYCODE_O | 43 |
| KEYCODE_P | 44 |
| KEYCODE_Q | 45 |
| KEYCODE_R | 46 |
| KEYCODE_S | 47 |
| KEYCODE_T | 48 |
| KEYCODE_U | 49 |
| KEYCODE_V | 50 |
| KEYCODE_W | 51 |
| KEYCODE_X | 52 |
| KEYCODE_Y | 53 |
| KEYCODE_Z | 54 |
| KEYCODE_COMMA | 55 |
| KEYCODE_PERIOD | 56 |
| KEYCODE_ALT_LEFT | 57 |
| KEYCODE_ALT_RIGHT | 58 |
| KEYCODE_SHIFT_LEFT | 59 |
| KEYCODE_SHIFT_RIGHT | 60 |
| KEYCODE_TAB | 61 |
| KEYCODE_SPACE | 62 |
| KEYCODE_SYM | 63 |
| KEYCODE_EXPLORER | 64 |
| KEYCODE_ENVELOPE | 65 |
| KEYCODE_ENTER | 66 |
| KEYCODE_DEL | 67 |
| KEYCODE_GRAVE | 68 |
| KEYCODE_MINUS | 69 |
| KEYCODE_EQUALS | 70 |
| KEYCODE_LEFT_BRACKET | 71 |
| KEYCODE_RIGHT_BRACKET | 72 |
| KEYCODE_BACKSLASH | 73 |
| KEYCODE_SEMICOLON | 74 |
| KEYCODE_APOSTROPHE | 75 |
| KEYCODE_SLASH | 76 |
| KEYCODE_AT | 77 |
| KEYCODE_NUM | 78 |
| KEYCODE_HEADSETHOOK | 79 |
| KEYCODE_FOCUS | 80 |
| KEYCODE_PLUS | 81 |
| KEYCODE_MENU | 82 |
| KEYCODE_NOTIFICATION | 83 |
| KEYCODE_SEARCH | 84 |
| TAG_LAST_ KEYCODE | 85 |
