-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathexecute_input.py
37 lines (29 loc) · 1002 Bytes
/
execute_input.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import os
import pipes
from toolchain import run_script
from commands import CMD_CURRENT_FOCUS
from commands import CMD_CALL_STATUSBAR
from commands import CMD_INPUT, CMD_DOUBLE_INPUT
cmd = os.getenv('function')
text = os.getenv('key')
mod = os.getenv('mod')
if cmd == "text":
text = pipes.quote(text.replace(" ", "%s"))
shell_cmd = ""
if cmd == "STATUS_BAR":
result = run_script(CMD_CURRENT_FOCUS)
expanded = "StatusBar" in result
shell_cmd = CMD_CALL_STATUSBAR.format(("1", "2")[expanded])
elif cmd == "KEYBOARD":
shell_cmd = CMD_INPUT.format(cmd, mod, text)
elif cmd == 'keyevent' and text == 'KEYCODE_BACK' and mod == 'alt':
shell_cmd = CMD_DOUBLE_INPUT.format(cmd, text)
elif cmd.startswith('keyevent_input_'):
shell_cmd = CMD_INPUT.format("keyevent", "", cmd[15:])
else:
shell_cmd = CMD_INPUT.format(cmd, ("", "--longpress")[mod == "cmd"], text)
try:
run_script(shell_cmd)
print("Executed: " + cmd)
except:
print("Failed to execute: adb "+cmd)