### Install @devicefarmer/minitouch-prebuilt Source: https://context7.com/devicefarmer/minitouch/llms.txt Install the npm package to easily embed prebuilt minitouch binaries in Node.js applications. ```bash npm install @devicefarmer/minitouch-prebuilt ``` -------------------------------- ### Initialize and Build Minitouch Binaries Source: https://context7.com/devicefarmer/minitouch/llms.txt Initializes the libevdev submodule and builds all ABI binaries using the Android NDK. Ensure NDK Revision 10 or later is installed. Use 'minitouch-nopie' for SDK versions below 16. ```bash git submodule init git submodule update ndk-build # Output binaries will be in ./libs//minitouch and ./libs//minitouch-nopie # Use minitouch-nopie for SDK < 16 (no PIE support) ``` -------------------------------- ### Chaotic Pinch Gesture with Minitouch Source: https://github.com/devicefarmer/minitouch/blob/master/README.md This example demonstrates a pinch gesture with a more randomized order of touch commands, simulating a less predictable interaction. Waits are crucial for timing. ```bash d 1 100 0 50 c d 0 0 100 50 c m 1 90 10 50 m 0 10 90 50 c m 0 20 80 50 c m 1 80 20 50 c m 0 20 80 50 m 1 80 20 50 c m 0 30 70 50 c m 1 70 30 50 c m 1 60 40 50 c m 0 40 60 50 c m 0 50 50 50 m 1 50 50 50 c u 0 c u 1 c ``` -------------------------------- ### Start Minitouch and Forward Socket Source: https://context7.com/devicefarmer/minitouch/llms.txt Ensure STFService is running, then start minitouch. It will automatically connect to minitouchagent on Android 10+. Forward the abstract socket to a local TCP port for connection. ```bash adb shell /data/local/tmp/minitouch adb forward tcp:1111 localabstract:minitouch nc localhost 1111 ``` -------------------------------- ### Swipe with Minitouch Source: https://github.com/devicefarmer/minitouch/blob/master/README.md Create a swipe gesture by defining a starting point, moving the contact incrementally, and then releasing it. Insert waits to control the swipe speed. ```bash d 0 0 0 50 c m 0 20 0 50 c m 0 40 0 50 c m 0 60 0 50 c m 0 80 0 50 c m 0 100 0 50 c u 0 c ``` -------------------------------- ### Run Minitouch on Device Source: https://github.com/devicefarmer/minitouch/blob/master/README.md Execute the Minitouch binary on the Android device. By default, it attempts to autodetect a touch device and starts listening on an abstract unix domain socket. ```bash adb shell /data/local/tmp/minitouch ``` -------------------------------- ### Get Device ABI Source: https://github.com/devicefarmer/minitouch/blob/master/README.md Determine the Android device's Application Binary Interface (ABI). This is necessary for pushing the correct Minitouch binary to the device. Note the removal of the carriage return character. ```bash ABI=$(adb shell getprop ro.product.cpu.abi | tr -d '\r') ``` -------------------------------- ### Display Minitouch Help Information Source: https://github.com/devicefarmer/minitouch/blob/master/README.md View the available command-line options for Minitouch. This is useful for understanding how to configure its behavior, such as input methods or device selection. ```bash adb shell /data/local/tmp/minitouch -h ``` -------------------------------- ### Minitouch Command-line Options Source: https://context7.com/devicefarmer/minitouch/llms.txt Demonstrates various command-line flags for minitouch, including showing help, selecting specific input devices, changing the socket name, enabling verbose mode, and using stdin or file input modes. ```bash # Show help adb shell /data/local/tmp/minitouch -h # Usage: /data/local/tmp/minitouch [-h] [-d ] [-n ] [-v] [-i] [-f ] # Use a specific input device instead of autodetect adb shell /data/local/tmp/minitouch -d /dev/input/event1 # Change the abstract socket name (default: "minitouch") adb shell /data/local/tmp/minitouch -n mydevice_touch # Verbose mode — logs each evdev event written to stderr adb shell /data/local/tmp/minitouch -v # stdin mode — read commands from stdin, no socket adb shell /data/local/tmp/minitouch -i # File mode — replay commands from a file, no socket adb shell /data/local/tmp/minitouch -f /data/local/tmp/gestures.txt ``` -------------------------------- ### Deploy Minitouch with run.sh Script Source: https://context7.com/devicefarmer/minitouch/llms.txt Automates the build and deployment of minitouch to a connected Android device. It detects the device's ABI and SDK version to select the correct binary. Extra flags can be passed to minitouch. ```bash # Single connected device ./run.sh # Multiple connected devices — set ANDROID_SERIAL first ANDROID_SERIAL=emulator-5554 ./run.sh # Pass extra flags to minitouch (e.g. verbose mode) ./run.sh -v ``` -------------------------------- ### Manual Minitouch Deployment via ADB Source: https://context7.com/devicefarmer/minitouch/llms.txt Manually pushes the appropriate minitouch binary to the device via ADB, makes it executable, and runs it. This method provides full control over minitouch options. It detects the device ABI and SDK to select the correct binary. ```bash # Detect device ABI (strip trailing CR from Android shell output) ABI=$(adb shell getprop ro.product.cpu.abi | tr -d ' ') SDK=$(adb shell getprop ro.build.version.sdk | tr -d ' ') # Select binary: minitouch-nopie for SDK < 16, minitouch otherwise if [ "$SDK" -ge 16 ]; then BIN=minitouch; else BIN=minitouch-nopie; fi # Push binary to writable temp directory adb push libs/$ABI/$BIN /data/local/tmp/minitouch # Make executable and run (starts socket server on abstract socket "minitouch") adb shell chmod +x /data/local/tmp/minitouch adb shell /data/local/tmp/minitouch # Expected stderr output: # Type B touch device Synaptics RMI4 (1080x1920 with 10 contacts) detected on /dev/input/event1 (score 11414) ``` -------------------------------- ### Resolve and Deploy Minitouch Binary with Node.js Source: https://context7.com/devicefarmer/minitouch/llms.txt Use the `getMinitouchBinary` function to resolve the correct prebuilt binary path based on ABI and SDK version. Then, push the binary to the device and make it executable using ADB commands. ```javascript const path = require('path') // Resolve the prebuilt binary for a given ABI function getMinitouchBinary(abi, sdk) { const binaryName = sdk >= 16 ? 'minitouch' : 'minitouch-nopie' return path.join( require.resolve('@devicefarmer/minitouch-prebuilt/package.json'), '..', 'prebuilt', abi, 'bin', binaryName ) } // Example: push binary for arm64-v8a device running SDK 30 const { execFileSync } = require('child_process') const localBin = getMinitouchBinary('arm64-v8a', 30) execFileSync('adb', ['push', localBin, '/data/local/tmp/minitouch']) execFileSync('adb', ['shell', 'chmod', '+x', '/data/local/tmp/minitouch']) console.log('minitouch deployed successfully') ``` -------------------------------- ### Initialize and Update Git Submodules Source: https://github.com/devicefarmer/minitouch/blob/master/README.md Fetch the libevdev submodule required for building Minitouch. Ensure this is run before invoking ndk-build. ```bash git submodule init git submodule update ``` -------------------------------- ### Build Minitouch with NDK Source: https://github.com/devicefarmer/minitouch/blob/master/README.md Compile Minitouch using the Android NDK. Binaries will be available in the ./libs directory after a successful build. ```bash ndk-build ``` -------------------------------- ### Generate config.h for libevdev Source: https://github.com/devicefarmer/minitouch/blob/master/jni/vendor/libevdev/README.md Creates an empty include/config.h file. This file is required for the libevdev build. ```bash touch include/config.h ``` -------------------------------- ### Connect to Minitouch Socket Source: https://context7.com/devicefarmer/minitouch/llms.txt Forwards the abstract Unix domain socket to a local TCP port and connects to it using netcat to receive the server header information. Note that only one connection is supported at a time. ```bash # Start minitouch on device (background) adb shell /data/local/tmp/minitouch & # Forward abstract socket "minitouch" to local TCP port 1111 adb forward tcp:1111 localabstract:minitouch # Connect — immediately receive 3 header lines nc localhost 1111 # v 1 <- protocol version (always first) # ^ 10 1080 1920 255 <- max_contacts max_x max_y max_pressure # $ 9876 <- PID of minitouch process # Note: only ONE connection at a time is supported ``` -------------------------------- ### Create and Replay Swipe Gesture File Source: https://context7.com/devicefarmer/minitouch/llms.txt Writes a swipe gesture command sequence to a file on the device and then replays it using minitouch's file mode, avoiding a persistent socket connection. ```bash # Create a swipe-right gesture file adb shell "cat > /data/local/tmp/swipe_right.txt" <<'EOF' d 0 100 960 50 c m 0 300 960 50 c m 0 500 960 50 c m 0 700 960 50 c m 0 980 960 50 c u 0 c EOF # Replay the file adb shell /data/local/tmp/minitouch -f /data/local/tmp/swipe_right.txt ``` -------------------------------- ### Push Minitouch Binary to Device Source: https://github.com/devicefarmer/minitouch/blob/master/README.md Transfer the compiled Minitouch binary to the device's temporary directory. Ensure the ABI is correctly identified and the binary path is accurate. ```bash adb push libs/$ABI/minitouch /data/local/tmp/ ``` -------------------------------- ### Connect to Minitouch Socket Source: https://github.com/devicefarmer/minitouch/blob/master/README.md Use netcat to connect to the locally forwarded port, which is now connected to the Minitouch socket on the device. Only one connection is supported at a time. ```bash nc localhost 1111 ``` -------------------------------- ### Tap with Minitouch Source: https://github.com/devicefarmer/minitouch/blob/master/README.md Use this snippet to perform a simple tap at specified coordinates with a given pressure. Ensure the contact is initialized and then committed. ```bash d 0 10 10 50 c u 0 c ``` -------------------------------- ### Execute Touch Up Command Source: https://context7.com/devicefarmer/minitouch/llms.txt Schedules a touch-up event to lift a finger from the screen for a specified contact. This must follow a 'd' command. ```bash # Full tap sequence: down, commit, up, commit printf "d 0 540 960 50\nc\nu 0\nc\n" | nc -q1 localhost 1111 ``` -------------------------------- ### Sequential Tap with Minitouch Source: https://github.com/devicefarmer/minitouch/blob/master/README.md Simulate a sequence of taps where one contact is held down while another is pressed and released. Use `` for timing. ```bash d 0 10 10 50 c d 1 20 20 50 c u 0 c u 1 c ``` -------------------------------- ### Forward Local Port to Minitouch Socket Source: https://github.com/devicefarmer/minitouch/blob/master/README.md Establish a TCP forward from your local machine to the abstract socket created by Minitouch on the device. This allows local clients to connect to Minitouch. ```bash adb forward tcp:1111 localabstract:minitouch ``` -------------------------------- ### Execute Wait Command Source: https://context7.com/devicefarmer/minitouch/llms.txt Pauses execution for a specified number of milliseconds on the device. This command executes immediately and does not require a commit. ```bash # Long-press: touch down, wait 800ms on device side, then lift printf "d 0 540 960 50\nc\nw 800\nu 0\nc\n" | nc -q1 localhost 1111 ``` -------------------------------- ### Protocol Version Source: https://github.com/devicefarmer/minitouch/blob/master/README.md Retrieves the protocol version from the minitouch server. This is the first message received upon connection. ```APIDOC ## GET /version ### Description Retrieves the protocol version from the minitouch server. This line is guaranteed to come first in the output. ### Endpoint v ### Response Example ``` v 1 ``` ``` -------------------------------- ### Simulate Pinch-to-Zoom Gesture Source: https://context7.com/devicefarmer/minitouch/llms.txt Executes a two-finger pinch inward gesture by moving contacts from opposite corners towards the center. Requires multiple move and commit commands. ```bash # Pinch from (0,100)+(100,0) converging to (50,50) — scale to real coords printf \ "d 0 0 100 50\nd 1 100 0 50\nc\n\ m 0 10 90 50\nm 1 90 10 50\nc\n\ m 0 20 80 50\nm 1 80 20 50\nc\n\ m 0 30 70 50\nm 1 70 30 50\nc\n\ m 0 40 60 50\nm 1 60 40 50\nc\n\ m 0 50 50 50\nm 1 50 50 50\nc\n\ u 0\nu 1\nc\n" | nc -q1 localhost 1111 ``` -------------------------------- ### Minitouch Protocol Version Source: https://github.com/devicefarmer/minitouch/blob/master/README.md The first line received from the socket indicates the protocol version. Check this to ensure compatibility with your client. ```text v 1 ``` -------------------------------- ### Schedule Touch Up Source: https://github.com/devicefarmer/minitouch/blob/master/README.md Schedules a touch up event for a specific contact. To move a contact before releasing it, use 'm' followed by a commit, then 'u'. Ensure no other 'd', 'm', or 'u' command exists for the same contact in the same commit. ```text u 0 ``` -------------------------------- ### Read Minitouch Header in Python Source: https://context7.com/devicefarmer/minitouch/llms.txt Reads the initial header information from the minitouch socket, including version, limits, and process ID. This is necessary before sending commands. ```python import socket, time s = socket.socket() s.connect(('localhost', 1111)) f = s.makefile('r') version_line = f.readline().strip() # "v 1" limits_line = f.readline().strip() # "^ 10 1080 1920 255" pid_line = f.readline().strip() # "$ 9876" _, max_contacts, max_x, max_y, max_pressure = limits_line.split() print(f"Device supports {max_contacts} contacts, resolution {max_x}x{max_y}") ``` -------------------------------- ### Simultaneous Tap with Minitouch Source: https://github.com/devicefarmer/minitouch/blob/master/README.md Execute a simultaneous tap with multiple contacts. Each contact needs to be defined with its ID, coordinates, and pressure, then committed together. ```bash d 0 10 10 50 d 1 20 20 50 c u 0 u 1 c ``` -------------------------------- ### Execute Commit Command Source: https://context7.com/devicefarmer/minitouch/llms.txt Flushes all pending touch events (d, m, u) to the screen. No visual changes occur until this command is issued. ```bash # Multitouch tap: two fingers down simultaneously, then both up printf "d 0 300 960 50\nd 1 780 960 50\nc\nu 0\nu 1\nc\n" | nc -q1 localhost 1111 ``` -------------------------------- ### Pinch Gesture with Minitouch Source: https://github.com/devicefarmer/minitouch/blob/master/README.md Implement a pinch gesture using two contacts. Define initial positions, move them towards each other incrementally, and then release. Use waits for smooth animation. ```bash d 0 0 100 50 d 1 100 0 50 c m 0 10 90 50 m 1 90 10 50 c m 0 20 80 50 m 1 80 20 50 c m 0 20 80 50 m 1 80 20 50 c m 0 30 70 50 m 1 70 30 50 c m 0 40 60 50 m 1 60 40 50 c m 0 50 50 50 m 1 50 50 50 c u 0 u 1 c ``` -------------------------------- ### Map Display Coordinates to Minitouch Space in Python Source: https://context7.com/devicefarmer/minitouch/llms.txt Provides a Python helper function to map display coordinates (pixels) to minitouch's internal touch-device coordinates, accounting for differences in resolution and touch digitizer space. It then uses these mapped coordinates to send a tap command. ```python # Python helper for coordinate mapping def map_coords(display_x, display_y, display_w, display_h, max_x, max_y): """Map display pixel coords to minitouch touch-device coords.""" touch_x = int(display_x / display_w * max_x) touch_y = int(display_y / display_h * max_y) return touch_x, touch_y # Example: tap center of a 1080x1920 display # Device reports max_x=4095, max_y=4095 (common for high-res digitizers) max_x, max_y = 4095, 4095 display_w, display_h = 1080, 1920 tx, ty = map_coords(540, 960, display_w, display_h, max_x, max_y) # tx=2047, ty=2047 import socket s = socket.socket() s.connect(('localhost', 1111)) f_r = s.makefile('r') # Read and discard header for _ in range(3): f_r.readline() cmd = f"d 0 {tx} {ty} 50\nc\nu 0\nc\n" s.sendall(cmd.encode()) s.close() ``` -------------------------------- ### Generate event-names.h for libevdev Source: https://github.com/devicefarmer/minitouch/blob/master/jni/vendor/libevdev/README.md Autogenerates the include/event-names.h file by processing input event header files using a Python script. This command should be re-run after updating the libevdev submodule. ```bash cat source/include/linux/input.h source/include/linux/input-event-codes.h | python source/libevdev/make-event-names.py > include/event-names.h ``` -------------------------------- ### Wait Command Source: https://github.com/devicefarmer/minitouch/blob/master/README.md Pauses execution for a specified number of milliseconds without committing any touch events. ```text w 50 ``` -------------------------------- ### Execute Touch Move Command Source: https://context7.com/devicefarmer/minitouch/llms.txt Schedules a touch-move event for an existing contact, updating its position and pressure. This is used for dragging actions. ```bash # Swipe from left to right across the screen (x: 100 → 980, y: 960) { printf "d 0 100 960 50\nc\n" for x in 200 300 400 500 600 700 800 900 980; do printf "m 0 %d 960 50\nc\n" $x sleep 0.02 done printf "u 0\nc\n" } | nc -q1 localhost 1111 ``` -------------------------------- ### Execute Touch Down Command Source: https://context7.com/devicefarmer/minitouch/llms.txt Schedules a touch-down event for a specific contact at given coordinates and pressure. This event is applied on the next commit. ```bash # Tap at (540, 960) — center of a 1080x1920 screen — with pressure 50 # contact 0, x=540, y=960, pressure=50 printf "d 0 540 960 50\nc\nu 0\nc\n" | nc -q1 localhost 1111 ``` -------------------------------- ### Simulate Single Tap Gesture Source: https://context7.com/devicefarmer/minitouch/llms.txt Performs a single tap at specified display coordinates using contact 0. Requires down, commit, up, and commit commands. ```bash # Tap at display coordinates (270, 480) on a 1080x1920 device printf "d 0 270 480 50\nc\nu 0\nc\n" | nc -q1 localhost 1111 ``` -------------------------------- ### Minitouch Socket Header Protocol Source: https://context7.com/devicefarmer/minitouch/llms.txt Defines the structure of the three header lines emitted by minitouch upon client connection, providing protocol version, hardware limits, and the minitouch process PID. ```text v 1 ^ 10 1080 1920 255 $ 9876 ``` -------------------------------- ### Schedule Touch Move Source: https://github.com/devicefarmer/minitouch/blob/master/README.md Schedules a touch move event for a specific contact to new coordinates with a given pressure. Ensure no other 'd', 'm', or 'u' command exists for the same contact in the same commit. ```text m 0 10 10 50 ``` -------------------------------- ### Long Tap with Minitouch Source: https://github.com/devicefarmer/minitouch/blob/master/README.md Perform a long tap by initiating a touch, committing it, and then releasing it after a delay. Replace `` with your desired pause. ```bash d 0 10 10 50 c u 0 c ``` -------------------------------- ### Schedule Touch Down Source: https://github.com/devicefarmer/minitouch/blob/master/README.md Schedules a touch down event for a specific contact at given coordinates and pressure. Ensure no other 'd', 'm', or 'u' command exists for the same contact in the same commit. ```text d 0 10 10 50 ``` -------------------------------- ### Minitouch Device Capabilities Source: https://github.com/devicefarmer/minitouch/blob/master/README.md This line reports the maximum values for contacts, X, Y, and pressure. Exceeding these bounds may lead to unexpected behavior or device freezes. ```text ^ 2 320 480 255 ``` -------------------------------- ### Execute Reset Command Source: https://context7.com/devicefarmer/minitouch/llms.txt Forcibly releases all active touch contacts by simulating 'u' events and committing them. Useful for recovering from a broken touch state. ```bash # Safety reset — send if you suspect a broken touch state printf "r\n" | nc -q1 localhost 1111 ``` -------------------------------- ### Process ID Source: https://github.com/devicefarmer/minitouch/blob/master/README.md Returns the process ID (PID) of the minitouch process. This can be useful for managing the process. ```APIDOC ## GET /pid ### Description Returns the process ID (PID) of the minitouch process. This can be useful for managing the process. ### Endpoint $ ### Response Example ``` $ 9876 ``` ``` -------------------------------- ### Reset Touches Command Source: https://github.com/devicefarmer/minitouch/blob/master/README.md Resets the current set of touches by scheduling 'touch up' events and committing them. Use this to recover from potentially invalid touch event sequences. ```text r ``` -------------------------------- ### Schedule Touch Move Source: https://github.com/devicefarmer/minitouch/blob/master/README.md Schedules a touch move event for a specific contact to new coordinates and pressure for the next commit. ```APIDOC ## POST /touch/move ### Description Schedules a touch move on a specific contact to the given coordinates with the specified pressure for the next commit. ### Method POST ### Endpoint m ### Parameters #### Path Parameters - **contact** (integer) - Required - The identifier for the touch contact. - **x** (integer) - Required - The new x-coordinate of the touch. - **y** (integer) - Required - The new y-coordinate of the touch. - **pressure** (integer) - Required - The pressure of the touch. ### Request Example ``` m 0 10 10 50 ``` ``` -------------------------------- ### Device Capabilities Source: https://github.com/devicefarmer/minitouch/blob/master/README.md Provides information about the touch device's capabilities, including maximum contacts, screen dimensions, and pressure limits. ```APIDOC ## GET /capabilities ### Description Provides the upper bounds of arguments for touch interactions, as reported by the touch device. Exceeding these values may lead to unexpected behavior. ### Endpoint ^ ### Response Example ``` ^ 2 320 480 255 ``` ``` -------------------------------- ### Schedule Touch Up Source: https://github.com/devicefarmer/minitouch/blob/master/README.md Schedules a touch up event for a specific contact for the next commit. ```APIDOC ## POST /touch/up ### Description Schedules a touch up on a specific contact. If the contact needs to move first, use a combination of 'm' and 'u' separated by a commit. ### Method POST ### Endpoint u ### Parameters #### Path Parameters - **contact** (integer) - Required - The identifier for the touch contact. ### Request Example ``` u 0 ``` ``` -------------------------------- ### Minitouch Process ID Source: https://github.com/devicefarmer/minitouch/blob/master/README.md Retrieves the process ID (PID) of the minitouch process, which can be used to terminate it. ```text $ 9876 ``` -------------------------------- ### Schedule Touch Down Source: https://github.com/devicefarmer/minitouch/blob/master/README.md Schedules a touch down event for a specific contact at given coordinates and pressure for the next commit. ```APIDOC ## POST /touch/down ### Description Schedules a touch down on a specific contact at the given coordinates with the specified pressure for the next commit. ### Method POST ### Endpoint d ### Parameters #### Path Parameters - **contact** (integer) - Required - The identifier for the touch contact. - **x** (integer) - Required - The x-coordinate of the touch. - **y** (integer) - Required - The y-coordinate of the touch. - **pressure** (integer) - Required - The pressure of the touch. ### Request Example ``` d 0 10 10 50 ``` ``` -------------------------------- ### Commit Touches Command Source: https://github.com/devicefarmer/minitouch/blob/master/README.md Commits the scheduled touch events to be executed on the screen. Changes are only visible after a commit. ```text c ``` -------------------------------- ### Wait Source: https://github.com/devicefarmer/minitouch/blob/master/README.md Pauses execution for a specified duration in milliseconds without committing any touch events. ```APIDOC ## POST /wait ### Description Immediately waits for the specified number of milliseconds. This command does not commit the queue or perform any other actions. ### Method POST ### Endpoint w ### Parameters #### Path Parameters - **ms** (integer) - Required - The duration to wait in milliseconds. ### Request Example ``` w 50 ``` ``` -------------------------------- ### Commit Touches Source: https://github.com/devicefarmer/minitouch/blob/master/README.md Commits the current set of scheduled touch events, causing them to be executed on the screen. ```APIDOC ## POST /commit ### Description Commits the current set of changed touches, causing them to play out on the screen. Note that nothing visible will happen until you commit. ### Method POST ### Endpoint c ### Request Example ``` c ``` ``` -------------------------------- ### Reset Touches Source: https://github.com/devicefarmer/minitouch/blob/master/README.md Resets the current set of touches by scheduling touch up events for all active contacts and then committing them. ```APIDOC ## POST /reset ### Description Attempts to reset the current set of touches by creating appropriate 'u' events and then committing them. Use this if you suspect an invalid sequence of events. ### Method POST ### Endpoint r ### Request Example ``` r ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.