Coder Social home page Coder Social logo

minitouch's Introduction

minitouch

Minitouch provides a socket interface for triggering multitouch events and gestures on Android devices. It works without root if started via ADB on at least SDK 25 and lower, though any version should work. The sole exception is SDK 20 (Android Wear), which does require root. The lowest SDK level we test is 10 (i.e. Android 2.3.3).

It works especially well with HTML5 multitouch events, and unlike the Android monkey tool, allows you to access the whole screen (including any software buttons).

Building

Building requires NDK, and is known to work with at least with NDK Revision 10 (July 2014). Note that NDK 15 no longer supports anything below Android SDK level 14, meaning that binaries may or may not work on older devices (e.g. Android 2.3).

We include libevdev as a Git submodule, so first make sure you've fetched it.

git submodule init
git submodule update

Then it's simply a matter of invoking ndk-build.

ndk-build

You should now have the binaries available in ./libs.

Running

You'll need to build first.

For Android 10 and up

Minitouch can't handle Android 10 by default, due to a new security policy. The workaround is to forward touch commands to STFService. If you are using minitouch standalone (without STF), you need to take care of running the service and agent, before running minitouch. Instructions on how to do that can be found here.

Running minitouch

You can then use the included run.sh script to run the right binary on your device. If you have multiple devices connected, set ANDROID_SERIAL before running the script.

To run manually, you have to first figure out which ABI your device supports:

ABI=$(adb shell getprop ro.product.cpu.abi | tr -d '\r')

Note that as Android shell always ends lines with CRLF, you'll have to remove the CR like above or the rest of the commands will not work properly.

Also note that if you've got multiple devices connected, setting $ANDROID_SERIAL will make things quite a bit easier as you won't have to specify the -s <serial> option every time.

Now, push the appropriate binary to the device:

adb push libs/$ABI/minitouch /data/local/tmp/

Note that for SDK <16, you will have to use the minitouch-nopie executable which comes without PIE support. Check run.sh for a scripting example.

At this point it might be useful to check the usage:

adb shell /data/local/tmp/minitouch -h

Currently, this should output be something along the lines of:

Usage: /data/local/tmp/minitouch [-h] [-d <device>] [-n <name>] [-v] [-i] [-f <file>]
  -d <device>: Use the given touch device. Otherwise autodetect.
  -n <name>:   Change the name of of the abtract unix domain socket. (minitouch)
  -v:          Verbose output.
  -i:          Uses STDIN and doesn't start socket.
  -f <file>:   Runs a file with a list of commands, doesn't start socket.
  -h:          Show help.

So, we can simply run the binary without any options, and it will try to detect an appropriate device and start listening on an abstract unix domain socket. Alternatively, you can start minitouch with the -i option and input commands directly via standard input, or -f <file> to read commands from a file.

adb shell /data/local/tmp/minitouch

If you chose to use a socket, you need to connect to it separately. Unless there was an error message and the binary exited, we should now have a server open on the device. Now we simply need to create a local forward so that we can connect to it.

adb forward tcp:1111 localabstract:minitouch

Now you can connect to the socket using the local port. Note that currently only one connection at a time is supported. This is mainly because it would otherwise be too easy to submit broken event streams, confusing the driver and possibly freezing the device until a reboot (which, by the way, you'd most likely have to do with adb reboot due to the unresponsive screen). Anyway, let's connect.

nc localhost 1111

The following section explains how to interact with minitouch.

Usage

It is assumed that you now have an open connection to the minitouch socket or you're running minitouch in stdin/file mode. If not, follow the instructions above.

The minitouch protocol is based on LF-separated lines. Each line is a separate command, and each line begins with a single ASCII letter which specifies the command type. Space-separated command-specific arguments then follow.

When you first open a connection to the socket, you'll receive a header with metadata which you'll need to read from the socket. Other than that there will be no responses of any kind.

Readable from the socket

v <version>

Example output: v 1

The protocol version. This line is guaranteed to come first in the output. Argument layout may change between versions, so you might want to check if your code supports this version or not.

^ <max-contacts> <max-x> <max-y> <max-pressure>

Example output: ^ 2 320 480 255

This gives you the upper bounds of arguments, as reported by the touch device. If you use larger values you will most likely confuse the driver (possibly freezing the screen, requiring a reboot) or the value will simply be ignored.

It's also very important to note that the maximum X and Y coordinates may, but usually do not, match the display size. You'll need to work out a good way to map display coordinates to touch coordinates if required, possibly by using percentages for screen coordinates.

$ <pid>

Example output: $ 9876

This is the pid of the minitouch process. Useful if you want to kill the process.

Writable to the socket

c

Example input: c

Commits the current set of changed touches, causing them to play out on the screen. Note that nothing visible will happen until you commit.

Commits are not required to list all active contacts. Changes from the previous state are enough.

Same goes for multi-contact touches. The contacts may move around in separate commits or even the same commit. If one contact moves, the others are not required to.

The order of touches in a single commit is not important either. For example you can list contact 5 before contact 0.

Note however that you cannot have more than one d, m or u for the same <contact> in one commit.

r

Example input: r

Attemps to reset the current set of touches by creating appropriate u events and then committing them. As an invalid sequence of events may cause the screen to freeze, you should call for a reset if you have any doubts about the integrity of your events. For example, two touchstart events for the same contact is very suspect and most likely means that you lost a touchend event somehow.

We try to discard obviously out-of-order events automatically, but sometimes it's not enough.

If the screen freezes you'll have to reboot the device. With careful use this will not happen.

d <contact> <x> <y> <pressure>

Example input: d 0 10 10 50

Schedules a touch down on contact <contact> at <x>,<y> with <pressure> pressure for the next commit.

You cannot have more than one d, m or u for the same <contact> in one commit.

m <contact> <x> <y> <pressure>

Example input: m 0 10 10 50

Schedules a touch move on contact <contact> at <x>,<y> with <pressure> pressure for the next commit.

You cannot have more than one d, m or u for the same <contact> in one commit.

u <contact>

Example input: u 0

Schedules a touch up on contact <contact>. If you need the contact to move first, use a combination of m and u separated by a commit.

You cannot have more than one d, m or u for the same <contact> in one commit.

w <ms>

Example input: w 50

Immediately waits for <ms> milliseconds. Will not commit the queue or do anything else.

Examples

Tap on (10, 10) with 50 pressure using a single contact.

d 0 10 10 50
c
u 0
c

Long tap on (10, 10) with 50 pressure using a single contact.

d 0 10 10 50
c
<wait in your own code>
u 0
c

Tap on (10, 10) and (20, 20) simultaneously with 50 pressure using two contacts.

d 0 10 10 50
d 1 20 20 50
c
u 0
u 1
c

Tap on (10, 10), keep it pressed, then after a while also tap on (20, 20), keep it pressed, then release the first contact and finally release the second contact.

d 0 10 10 50
c
<wait in your own code>
d 1 20 20 50
c
<wait in your own code>
u 0
c
<wait in your own code>
u 1
c

Swipe from (0, 0) to (100, 0) using a single contact. You'll need to wait between commits in your own code to slow it down.

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

Pinch with two contacts going from (0, 100) to (50, 50) and (100, 0) to (50, 50). You'll need to wait between commits in your own code to slow it down.

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

The same pinch but with more chaotic (or natural) ordering.

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

Contributing

See CONTRIBUTING.md.

License

See LICENSE.

Copyright © CyberAgent, Inc. All Rights Reserved.

minitouch's People

Contributors

denis99999 avatar dependabot-preview[bot] avatar koral-- avatar mumblepins avatar pcrepieux avatar sorccu avatar stoefln avatar tbmc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

minitouch's Issues

Request for Windows-specific installation steps

Hello, guys,

I would like to request the addition of Windows-specific installation steps and instructions for Minitouch. As a Windows user, I believe that having clear guidance for installing and running Minitouch on Windows would be beneficial. This would help expand the accessibility of Minitouch to a wider user base.

Thank you for your attention to this matter.

Best regards,
Yucheng Song

Possible Typo in Documentation: "Running minicap" Section Title

Hello guys,

I was going through the minitouch documentation and noticed a potential typo in the section title. The section currently titled "Running minicap" seems to contain information relevant to "minitouch" rather than "minicap."

Given the context and content, it appears that the section title might be a typographical error and could potentially be corrected to "Running minitouch." This would align the title with the information presented in the section.

This could be found in the README.md file or directly at this link.

Thank you for your attention to this matter, and for your continuous efforts in maintaining this valuable project.

Best regards,
Yucheng Song

minitouch can not run in android 14(not root),Does anyone know how to solve it?

minitouch cannot be used on non-rooted Android 14 models and will report a permission error. How can I solve it?
The error message is as follows:

open: Permission denied
Unable to open device /dev/input/event0 for inspectionopen: Permission denied
Unable to open device /dev/input/mice for inspectionopen: Permission denied
Unable to open device /dev/input/mouse1 for inspectionopen: Permission denied
Unable to open device /dev/input/event5 for inspectionopen: Permission denied
Unable to open device /dev/input/mouse0 for inspectionopen: Permission denied
Unable to open device /dev/input/event2 for inspectionopen: Permission denied
Unable to open device /dev/input/event3 for inspectionopen: Permission denied
Unable to open device /dev/input/event1 for inspectionopen: Permission denied
Unable to open device /dev/input/event4 for inspectionUnable to find a suitable touch device
connecting socket: Connection refused

Issue with minitouch not terminating properly on SIGINT (Ctrl+C) on Win-PS

Hi, guys,
I've encountered an issue where minitouch does not terminate properly when I send a SIGINT signal (using Ctrl+C) in the Win-PS terminal. After terminating minitouch with Ctrl+C, attempting to run it again results in a "binding socket: Address already in use" error. This suggests that the previous instance of minitouch did not release the port it was using.

Steps to Reproduce:

  1. Start minitouch on an Android emulator/device using the command: adb shell /data/local/tmp/minitouch.
  2. Terminate minitouch using Ctrl+C.
  3. Attempt to run minitouch again using the same command.

Expected Behavior:
Minitouch should terminate gracefully upon receiving a SIGINT signal and release any resources it was using, including the port.

Actual Behavior:
Minitouch does not seem to release the port it was bound to, leading to a "binding socket: Address already in use" error upon attempting to run it again.

Environment:

  • Operating System: Windows 10
  • Android device/emulator model: emulator-5554
  • Android version: Android 7.1.2

Additional Information:

  • Running adb -s emulator-5554 shell ps | findstr minitouch confirms that the minitouch process is still running after attempting to terminate it with Ctrl+C.
  • Temporary workaround: Manually killing the process using adb shell kill [PID] allows minitouch to be run again.

I believe this might be a bug with how minitouch handles the SIGINT signal. Any assistance or insights into this issue would be greatly appreciated.

Run minitouch on Android 11

Hi, i'm facing a problem to use minitouch on Android 11 devices. I know there are some security policies that make it difficult to use, but on the readme it wrote that we can use it with the STFService.

But i well followed instructions to run the STFService. It seems to works well, when i start the agent, it print bin jp.co.cyberagent.stf.Agent Starting minitouch agent Listening on @stfagent

But when i send command through netcat to this socket, nothing happens, and when i build and use minitouch, it doesn't works too (got the normal error /dev/input/event )

What did i missed ?

Thanks for your answer.
Regards, Bastien

vmos andoird7

WARNING: linker: /data/local/tmp/minitouch: unsupported flags DT_FLAGS_1=0x8000001
opendir: Permission denied
Unable to crawl /dev/input for touch devices

max-x and max-y change place when device is rotated

I have problems with implementing the coordinate mapping for my Pixel 3a. (I am not using stf, that's why I have my own implementation).

The problem is: my Pixel 3A is switching the max-x and max-y coordinates when I reconnect my device.
Any ideas what's going on? How should I deal with this? My mapping does not account for device specific transformations...

Pixel 3a (max-x and max-y switch places)

Landscape
^ 10 2220 1080 0

Portrait
^ 10 1080 2220 0

Tab2 (max-x and max-y stay the same):

Landscape
^ 10 1535 2047 255

Portrait
^ 10 1535 2047 255

magisk 21.2 not working

There was a problem starting the server on magisk 21.2 on version 20.4 working fine.

D/MinitouchSocket12: Note: device /dev/input/mice is not supported by libevdevType B touch device NVTCapacitiveTouchScreen (1080x2160 with 10 contacts) detected on /dev/input/event1 (score 2109) binding socket: Address already in useUnable to start server on minitouch

Suggest updating libevdev dependency to the latest version (1.13.1)

Hello, guys,

I have noticed that the current version of libevdev being used in the minitouch project is outdated. The latest version available for libevdev is 1.13.1, which includes new features, performance improvements, and potential security updates.

Updating the libevdev dependency in minitouch would help ensure that the project stays up-to-date and continues to benefit from the latest developments in the libevdev library.

Thank you for your attention to this matter, and I look forward to seeing minitouch continue to evolve and improve.

Best regards,
Yucheng Song

Minitouch giving error on realme device with android 14

I am using stf and while enrolling the realme device with android 14, minitouch is failing and giving below error logs:

open: Permission denied
Unable to open device /dev/input/event4 for inspectionopen: Permission denied
Unable to open device /dev/input/event2 for inspectionopen: Permission denied
Unable to open device /dev/input/event3 for inspectionopen: Permission denied
Unable to open device /dev/input/event0 for inspectionopen: Permission denied
Unable to open device /dev/input/event1 for inspectionUnable to find a suitable touch device
connecting socket: Connection refused

it will retry thrice and then will get failed.

what could be the potential issue here?

Integration with AutoIT

I am using AutoIt, and i believe you can use the the minitouch to inject touches into android emulator examples below

Is there a guide or tutorial on how to use it in AutoIt?

Any help will really be appreciated

Example
r
d 0 300 590 50
d 1 560 590 50
c
w 50
m 0 325 590 50
m 1 535 590 50
c
w 50
m 0 350 590 50
m 1 510 590 50
c
w 50
m 0 375 590 50
m 1 485 590 50
c
w 50
m 0 400 590 50
m 1 460 590 50
c
w 50
m 0 425 590 50
m 1 435 590 50
c
w 50
m 0 430 590 50
m 1 430 590 50
c
w 50
u 0
u 1
c

🐛 Bug: Gestures ignored on right-side landscape

Description:

Gestures ignored when the device is stored on its right-side w/ landscape mode on, as soon as the device is rotated to its left-side gestures work correctly again.

Noticed on devices w/ versions: Android 11, Android 12 (Android 12 also has a problem with minicap in the landscape mode).
Minitouch consumer/environment: STF

Steps To Reproduce

  • Connect an Android 11/12 (sdk 30/31?) to the STF
  • Start using the device in portrait mode
    • If autorotate is off - switch on
    • Open Settings (or any application supports landscape mode)
  • Rotate the actual device on its right-side (the window should be in landscape mode)
    • Try to manipulate via the browser - commands not reflected
  • Rotate the actual device on its left-side (the window should be in landscape mode)
    • Try to manipulate via the browser - now it works

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.