### Install pyminitouch using pip Source: https://github.com/williamfzc/pyminitouch/blob/master/README.md This command installs the pyminitouch library using pip, the Python package installer. Ensure you are using Python 3. ```bash pip install pyminitouch ``` -------------------------------- ### PyMiniTouch Drawing Shapes with CommandBuilder Source: https://context7.com/williamfzc/pyminitouch/llms.txt Shows how to draw complex shapes, like a heart, by chaining multiple move commands with the CommandBuilder. This example illustrates creating intricate paths on the screen using sequential touch movements. ```python from pyminitouch import safe_connection, CommandBuilder _DEVICE_ID = '123456F' with safe_connection(_DEVICE_ID) as connection: builder = CommandBuilder() # Start at bottom point of heart builder.down(0, 400, 800, 50) builder.commit() # Draw left side of heart builder.move(0, 0, 400, 50) builder.commit() builder.move(0, 200, 200, 50) builder.commit() # Draw top center builder.move(0, 400, 400, 50) builder.commit() # Draw right side of heart builder.move(0, 600, 200, 50) builder.commit() builder.move(0, 800, 400, 50) builder.commit() # Return to bottom builder.move(0, 400, 800, 50) builder.commit() # Release builder.up(0) builder.commit() builder.publish(connection) ``` -------------------------------- ### PyMiniTouch Utility Functions - ADB and Device Checks Source: https://context7.com/williamfzc/pyminitouch/llms.txt Provides examples of using utility functions from PyMiniTouch for managing ADB (restarting the server) and checking device connectivity and port usage. These functions are helpful for troubleshooting connection issues. ```python from pyminitouch.utils import restart_adb, is_device_connected, is_port_using # Restart ADB server (useful for connection issues) restart_adb() # Check if a specific device is connected device_id = '123456F' if is_device_connected(device_id): print(f"Device {device_id} is online") else: print(f"Device {device_id} is not connected") # Check if a port is in use port = 20000 if is_port_using(port): print(f"Port {port} is already in use") else: print(f"Port {port} is available") ``` -------------------------------- ### Build and Publish Custom Touch Commands with CommandBuilder Source: https://github.com/williamfzc/pyminitouch/blob/master/docs/index.md Demonstrates how to manually construct a sequence of touch actions using the CommandBuilder class and publish them to a device connection. This approach provides granular control over individual touch events like down, move, and up. ```python with safe_connection(_DEVICE_ID) as connection: builder = CommandBuilder() builder.down(0, 400, 400, 50) builder.commit() builder.move(0, 500, 500, 50) builder.commit() builder.move(0, 800, 400, 50) builder.commit() builder.up(0) builder.commit() builder.publish(connection) ``` -------------------------------- ### Basic Device Interaction with pyminitouch Source: https://github.com/williamfzc/pyminitouch/blob/master/README.md Demonstrates how to initialize an MNTDevice, perform single and multi-taps with customizable pressure, and properly stop the service. This requires the device ID. ```python from pyminitouch import MNTDevice _DEVICE_ID = '123456F' device = MNTDevice(_DEVICE_ID) # single-tap device.tap([(400, 600)]) # multi-tap device.tap([(400, 400), (600, 600)]) # set the pressure, default == 100 device.tap([(400, 600)], pressure=50) # ... and something else you want, just like minitouch itself! # and, after usage, you MUST call function `stop` to stop service device.stop() ``` -------------------------------- ### Performing Basic Touch Operations with MNTDevice Source: https://context7.com/williamfzc/pyminitouch/llms.txt Demonstrates how to initialize an MNTDevice, query screen dimensions, and perform various touch actions like single-tap, multi-tap, and swipe gestures. The device must be manually stopped after use. ```python from pyminitouch import MNTDevice import time _DEVICE_ID = '123456F' device = MNTDevice(_DEVICE_ID) print('max x: ', device.connection.max_x) print('max y: ', device.connection.max_y) device.tap([(400, 600)]) device.tap([(400, 400), (600, 600)]) device.tap([(400, 600)], pressure=50) device.tap([(400, 600)], duration=2000) time.sleep(2) device.tap([(400, 600)], no_up=True) device.swipe([(100, 100), (500, 500)]) device.swipe([(100, 100), (400, 400), (200, 400)], duration=500, pressure=50) device.ext_smooth_swipe([(100, 100), (400, 400), (200, 400)], duration=500, pressure=50, part=20) device.stop() ``` -------------------------------- ### PyMiniTouch Multi-Touch Gestures with CommandBuilder Source: https://context7.com/williamfzc/pyminitouch/llms.txt Demonstrates how to simulate multi-finger gestures, such as a two-finger tap and pinch, by using different contact IDs (0, 1, etc.) with the CommandBuilder. This allows for complex interactions requiring simultaneous touches. ```python from pyminitouch import safe_connection, CommandBuilder _DEVICE_ID = '123456F' with safe_connection(_DEVICE_ID) as connection: builder = CommandBuilder() # Two-finger tap (pinch start position) builder.down(0, 300, 500, 50) # First finger builder.down(1, 500, 500, 50) # Second finger builder.commit() # Wait to simulate hold builder.wait(500) builder.commit() # Move fingers apart (pinch out gesture) builder.move(0, 200, 500, 50) # First finger moves left builder.move(1, 600, 500, 50) # Second finger moves right builder.commit() # Release both fingers builder.up(0) builder.up(1) builder.commit() builder.publish(connection) ``` -------------------------------- ### PyMiniTouch CommandBuilder - Build Custom Touch Sequences Source: https://context7.com/williamfzc/pyminitouch/llms.txt Demonstrates using the CommandBuilder to construct and send a sequence of touch commands (down, move, wait, up) to a device via a safe connection. This allows for fine-grained control over touch interactions. ```python from pyminitouch import safe_connection, CommandBuilder _DEVICE_ID = '123456F' with safe_connection(_DEVICE_ID) as connection: builder = CommandBuilder() # Press down: contact_id=0, x=400, y=400, pressure=50 builder.down(0, 400, 400, 50) builder.commit() # Send 'c' command to execute buffered commands # Move finger to new position builder.move(0, 500, 500, 50) builder.commit() # Continue moving builder.move(0, 800, 400, 50) builder.commit() # Wait 500ms before next action builder.wait(500) builder.commit() # Lift finger builder.up(0) builder.commit() # Send all commands to the device builder.publish(connection) ``` -------------------------------- ### PyMiniTouch safe_connection - Raw Minitouch Protocol Source: https://context7.com/williamfzc/pyminitouch/llms.txt Illustrates using the safe_connection context manager to establish a direct socket connection to the minitouch service. It shows how to access connection properties and send raw minitouch commands directly for maximum control. ```python from pyminitouch import safe_connection _DEVICE_ID = '123456F' # Using CommandBuilder with safe_connection with safe_connection(_DEVICE_ID) as connection: # Access connection properties print(f"Port: {connection.port}") print(f"PID: {connection.pid}") print(f"Max X: {connection.max_x}") print(f"Max Y: {connection.max_y}") print(f"Max Contacts: {connection.max_contacts}") print(f"Max Pressure: {connection.max_pressure}") # Send raw minitouch commands directly # Format: d \n - press down # m \n - move # u \n - release # c\n - commit (execute buffered commands) # w \n - wait raw_commands = """d 0 150 150 50 c u 0 c """ connection.send(raw_commands) ``` -------------------------------- ### Creating Complex Gestures via Action Chaining Source: https://context7.com/williamfzc/pyminitouch/llms.txt Shows how to build sophisticated gestures like drag-and-drop by chaining multiple touch actions using the no_down and no_up parameters to maintain continuous contact with the screen. ```python from pyminitouch import safe_device import time _DEVICE_ID = '123456F' with safe_device(_DEVICE_ID) as device: device.tap([(400, 600)], duration=2000, no_up=True) device.swipe([(400, 600), (400, 400), (200, 400)], duration=500, pressure=50, no_down=True, no_up=True) device.swipe([(200, 400), (400, 400), (400, 600)], duration=500, pressure=50, no_down=True) ``` -------------------------------- ### CommandBuilder API Source: https://github.com/williamfzc/pyminitouch/blob/master/docs/index.md Low-level command construction for minitouch protocol commands. ```APIDOC ## CommandBuilder ### Description Builds raw minitouch command strings to be sent to the device connection. ### Methods - **down(contact_id, x, y, pressure)**: Adds a 'down' event. - **move(contact_id, x, y, pressure)**: Adds a 'move' event. - **up(contact_id)**: Adds an 'up' event. - **commit()**: Commits the current batch of commands. - **publish(connection)**: Sends the built command buffer to the device. ### Request Example ```python builder = CommandBuilder() builder.down(0, 400, 400, 50) builder.commit() builder.publish(connection) ``` ``` -------------------------------- ### Perform Device Interactions with MNTDevice Source: https://github.com/williamfzc/pyminitouch/blob/master/docs/index.md Shows how to use the MNTDevice class to perform common touch operations such as tapping, swiping, and smooth swiping. It also demonstrates how to retrieve device screen dimensions and manage the device lifecycle. ```python device = MNTDevice(_DEVICE_ID) print('max x: ', device.connection.max_x) print('max y: ', device.connection.max_y) # single-tap device.tap([(400, 600)]) # multi-tap device.tap([(400, 400), (600, 600)]) # swipe device.swipe([(100, 100), (500, 500)]) # smooth swipe device.ext_smooth_swipe([(100, 100), (400, 400), (200, 400)], duration=500, pressure=50, part=20) device.stop() ``` -------------------------------- ### Managing Device Lifecycle with safe_device Source: https://context7.com/williamfzc/pyminitouch/llms.txt Uses the safe_device context manager to automatically handle the initialization and cleanup of the MNTDevice connection, ensuring resources are released even if errors occur. ```python from pyminitouch import safe_device _DEVICE_ID = '123456F' with safe_device(_DEVICE_ID) as device: device.tap([(400, 600)]) device.tap([(400, 400), (600, 600)]) device.tap([(400, 600)], pressure=50) device.swipe([(100, 100), (500, 500)]) ``` -------------------------------- ### MNTDevice Touch Actions Source: https://github.com/williamfzc/pyminitouch/blob/master/docs/index.md High-level methods for performing touch interactions like tapping and swiping on an Android device. ```APIDOC ## MNTDevice Touch Actions ### Description Perform touch operations such as single/multi-tap and swipe gestures on an Android device. ### Methods - **tap(points, pressure=100, duration=None, no_up=None)**: Perform a tap at specified coordinates. - **swipe(points, pressure=100, duration=None, no_down=None, no_up=None)**: Perform a swipe gesture through a list of points. - **ext_smooth_swipe(points, pressure=100, duration=None, part=10, ...)**: Perform a smooth swipe by interpolating points. ### Parameters - **points** (list of tuples) - Required - List of (x, y) coordinates. - **pressure** (int) - Optional - Pressure value (default 100). - **duration** (int) - Optional - Duration in milliseconds. ### Request Example ```python device = MNTDevice(device_id) device.tap([(400, 600)], pressure=50, duration=1000) device.swipe([(100, 100), (500, 500)]) ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.