Generic setup for scripting an Android device via ADB.
adb_tools/
├── platform-tools/
│ └── adb.exe # ADB executable
├── helper/
│ ├── find_coords.py # Click on the screen to get coordinates + RGB
│ └── make_a_screen.py # Capture a region of the screen in PNG
├── tools/
│ ├── __init__.py
│ └── adb.py # All ADB functions
├── check_id.py # List all connected devices
├── config.json # Device ID of the target device
└── README.md
- Install dependencies:
pip install pillow matplotlib- Fill the
device_idinconfig.json(usecheck_id.pyto find it)
from tools import tap, swipe, write, compare_image, is_color, stop, path
tap(500, 300)
hold(500, 300, ms=800) # Hold right button for 800ms
swipe(100, 800, 100, 200)
write("hello world")
enter() # Enter key
delete() # Delete key
# Image - relative path to the project root
if not compare_image(path("img/example.png"), (0, 0, 200, 100)):
stop("Example image not found")
# Color
if is_color(540, 960, (255, 0, 0)):
tap(540, 960)| Script | Usage |
|---|---|
check_id.py |
Display all connected ADB devices |
helper/find_coords.py |
Capture the screen, click to get coordinates + RGB |
helper/make_a_screen.py |
Capture a defined region and save it in PNG |