A python module to control your android phone
- Pip
- adb installed and added to PATH
Open a command prompt and run:
pip install android_controller
Open a command promp and clone this repo. Now cd to that folder and run:
pip install .
The package can be imported using:
import android_controller
Most of the times devices connect to adb automatically, but if they don't you can use:
android_controller.connect(host) #host is where your device is connected to. For example, bluestacks would be localhost:5555
You can then check which devices are connected using:
connections = android_controller.checkConnections()
This will return a list with the names of all connected devices. Please make sure you only have one device connected, otherwise the module might not work properly.
android_controller.checkConnections()
Returns a list of all devices currently connected.
android_controller.connect(host: str)
Connects to the chosen host.
android_controller.disconnect(host: str)
Disconnects from the chosen host. If no host is defined, disconnects from all hosts.
android_controller.keyEvent(key: str, longpress: bool)
Executes a keyevent. Set longpress to True for a longpress.
android_controller.screenshot(outputpath: str)
Makes a screenshot and saves it at the defined location.
android_controller.swipe(x1: int, y1: int, x2: int, y2: int)
Swipes from the first location to the second location.
android_controller.tap(x: int, y: int)
Taps at the defined location.
All distributions are welcome. There are quite some functions that are less commonly used I left out, but they can of course still be added.
This project is licensed under the MIT license.