-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadb_commands.py
More file actions
99 lines (72 loc) · 2.49 KB
/
Copy pathadb_commands.py
File metadata and controls
99 lines (72 loc) · 2.49 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import subprocess
import uuid
import os
import re
import time
from constants import COMPLIMENTS, EMOJI_REGEX
def_dump_path = "/sdcard/window_dump.xml"
def run_command(command):
process = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True)
output, error = process.communicate()
def tap(x, y):
run_command(f"adb shell input tap {x} {y}")
def double_tap(x, y):
tap(x, y)
tap(x, y)
def long_tap(x, y, duration):
run_command(f"adb shell input swipe {x} {y} {x} {y} {duration}")
def swipe(x1, y1, x2, y2):
run_command(f"adb shell input swipe {x1} {y1} {x2} {y2}")
def dump():
dump_file_name = str(uuid.uuid4())
run_command(f"adb shell uiautomator dump")
run_command(f"adb pull {def_dump_path} ./dump/{dump_file_name}.xml")
return f"./dump/{dump_file_name}.xml"
# Read about the service https://www.makeuseof.com/share-clipboard-with-android-adb/
def _copy_to_clipboard(text):
if text is None:
return
# formatted_text = text.replace(' ', '%s')
run_command(f"adb shell am broadcast -a clipper.set -e text '{text}'")
def _type(text):
if text is None:
return
os.system(f"adb shell input text '{text}'")
def paste():
os.system("adb shell input keyevent KEYCODE_PASTE")
def type(message):
processed_string = message.replace(" ", "%s")
processed_string = processed_string.replace(
"'", ""
) # TODO work on quotes later, use keyevent 62, 75, 74
processed_string = processed_string.replace(
'"', ""
) # TODO work on quotes later, see specialChar
# Regex to identify emojis
emoji_pattern = re.compile(
EMOJI_REGEX,
flags=re.UNICODE,
)
# Split the string into text and emojis
parts = emoji_pattern.split(processed_string)
emojis = emoji_pattern.findall(processed_string)
# Iterate over the parts and emojis
for part, emoji in zip(parts, emojis + [""]):
if part:
_type(part)
if emoji:
_copy_to_clipboard(emoji)
paste()
# TODO write logic for special keys like single, double quote
def specialChar(message):
for char in message:
if char == " ":
os.system("adb shell input keyevent 62")
elif char == "'":
os.system("adb shell input keyevent 75")
elif char == '"':
os.system("adb shell input keyevent 74")
else:
os.system(f"adb shell input text '{char}'")
def goBack():
os.system("adb shell input keyevent KEYCODE_BACK")