Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
340 lines (247 loc) · 14.6 KB
/
Copy pathindex.html
File metadata and controls
340 lines (247 loc) · 14.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="UTF-8">
<title>Minitouch by openstf</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="stylesheets/normalize.css" media="screen">
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="stylesheets/stylesheet.css" media="screen">
<link rel="stylesheet" type="text/css" href="stylesheets/github-light.css" media="screen">
</head>
<body>
<section class="page-header">
<h1 class="project-name">Minitouch</h1>
<h2 class="project-tagline">Minimal multitouch event producer for Android.</h2>
<a href="https://github.com/openstf/minitouch" class="btn">View on GitHub</a>
<a href="https://github.com/openstf/minitouch/zipball/master" class="btn">Download .zip</a>
<a href="https://github.com/openstf/minitouch/tarball/master" class="btn">Download .tar.gz</a>
</section>
<section class="main-content">
<h1>
<a id="minitouch" class="anchor" href="#minitouch" aria-hidden="true"><span class="octicon octicon-link"></span></a>minitouch</h1>
<p>Minitouch provides a socket interface for triggering multitouch events and gestures on Android devices. It works without root if started via <a href="http://developer.android.com/tools/help/adb.html">ADB</a> on SDK 21 or lower. 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).</p>
<p>It works especially well with HTML5 multitouch events, and unlike the Android <a href="http://developer.android.com/tools/help/monkey.html">monkey</a> tool, allows you to access the whole screen (including any software buttons).</p>
<h2>
<a id="building" class="anchor" href="#building" aria-hidden="true"><span class="octicon octicon-link"></span></a>Building</h2>
<p>Building requires <a href="https://developer.android.com/tools/sdk/ndk/index.html">NDK</a>, and is known to work with at least with NDK Revision 10 (July 2014).</p>
<p>We include <a href="http://www.freedesktop.org/wiki/Software/libevdev/">libevdev</a> as a Git submodule, so first make sure you've fetched it.</p>
<pre><code>git submodule init
git submodule update
</code></pre>
<p>Then it's simply a matter of invoking <code>ndk-build</code>.</p>
<pre><code>ndk-build
</code></pre>
<p>You should now have the binaries available in <code>./libs</code>.</p>
<h2>
<a id="running" class="anchor" href="#running" aria-hidden="true"><span class="octicon octicon-link"></span></a>Running</h2>
<p>You'll need to <a href="#building">build</a> first. You can then use the included <a href="run.sh">run.sh</a> script to run the right binary on your device. If you have multiple devices connected, set <code>ANDROID_SERIAL</code> before running the script.</p>
<p>To run manually, you have to first figure out which ABI your device supports:</p>
<div class="highlight highlight-bash"><pre>ABI=<span class="pl-s"><span class="pl-pds">$(</span>adb shell getprop ro.product.cpu.abi <span class="pl-k">|</span> tr -d <span class="pl-s"><span class="pl-pds">'</span>\r<span class="pl-pds">'</span></span><span class="pl-pds">)</span></span></pre></div>
<p><em>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.</em></p>
<p><em>Also note that if you've got multiple devices connected, setting <code>$ANDROID_SERIAL</code> will make things quite a bit easier as you won't have to specify the <code>-s <serial></code> option every time.</em></p>
<p>Now, push the appropriate binary to the device:</p>
<div class="highlight highlight-bash"><pre>adb push libs/<span class="pl-smi">$ABI</span>/minitouch /data/local/tmp/</pre></div>
<p>Note that for SDK <16, you will have to use the <code>minitouch-nopie</code> executable which comes without <a href="http://en.wikipedia.org/wiki/Position-independent_code#Position-independent_executables">PIE</a> support. Check <a href="run.sh">run.sh</a> for a scripting example.</p>
<p>At this point it might be useful to check the usage:</p>
<div class="highlight highlight-bash"><pre>adb shell /data/local/tmp/minitouch -h</pre></div>
<p>Currently, this should output be something along the lines of:</p>
<pre><code>Usage: /data/local/tmp/minitouch [-h] [-d <device>] [-n <name>]
-d <device>: Use the given touch device. Otherwise autodetect.
-n <name>: Change the name of of the abtract unix domain socket. (minitouch)
-h: Show help.
</code></pre>
<p>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.</p>
<div class="highlight highlight-bash"><pre>adb shell /data/local/tmp/minitouch</pre></div>
<p>Unless there was an error message and the binary exited, we should now have a socket open on the device. Now we simply need to create a local forward so that we can connect to the socket.</p>
<div class="highlight highlight-bash"><pre>adb forward tcp:1111 localabstract:minitouch</pre></div>
<p>Now you can connect to the socket using the local port. Note that currently <strong>only one connection at a time is supported.</strong> 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 <code>adb reboot</code> due to the unresponsive screen). Anyway, let's connect.</p>
<div class="highlight highlight-bash"><pre>nc localhost 1111</pre></div>
<p>This will give you some strange output that will be explained in the next section.</p>
<h2>
<a id="usage" class="anchor" href="#usage" aria-hidden="true"><span class="octicon octicon-link"></span></a>Usage</h2>
<p>It is assumed that you now have an open connection to the minitouch socket. If not, follow the <a href="#running">instructions</a> above.</p>
<p>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.</p>
<p>When you first open a connection to the socket, you'll get some protocol metadata which you'll need need to read from the socket. Other than that there will be no responses of any kind.</p>
<h3>
<a id="readable-from-the-socket" class="anchor" href="#readable-from-the-socket" aria-hidden="true"><span class="octicon octicon-link"></span></a>Readable from the socket</h3>
<h4>
<a id="v-version" class="anchor" href="#v-version" aria-hidden="true"><span class="octicon octicon-link"></span></a><code>v <version></code>
</h4>
<p>Example output: <code>v 1</code></p>
<p>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.</p>
<h4>
<a id="-max-contacts-max-x-max-y-max-pressure" class="anchor" href="#-max-contacts-max-x-max-y-max-pressure" aria-hidden="true"><span class="octicon octicon-link"></span></a><code>^ <max-contacts> <max-x> <max-y> <max-pressure></code>
</h4>
<p>Example output: <code>^ 2 320 480 255</code></p>
<p>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.</p>
<p>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.</p>
<h3>
<a id="writable-to-the-socket" class="anchor" href="#writable-to-the-socket" aria-hidden="true"><span class="octicon octicon-link"></span></a>Writable to the socket</h3>
<h4>
<a id="c" class="anchor" href="#c" aria-hidden="true"><span class="octicon octicon-link"></span></a><code>c</code>
</h4>
<p>Example input: <code>c</code></p>
<p>Commits the current set of changed touches, causing the to play out on the screen. Nothing visible will happen until the commit, but depending on the device type, they may already have been buffered.</p>
<p>Commits are not required to list all active contacts. Changes from the previous state are enough.</p>
<p>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.</p>
<p>The order of touches in a single commit is not important either. For example you can list contact 5 before contact 0.</p>
<p>Note however that you cannot have more than one <code>d</code>, <code>m</code> or <code>u</code> <em>for the same <code><contact></code></em> in one commit.</p>
<h4>
<a id="r" class="anchor" href="#r" aria-hidden="true"><span class="octicon octicon-link"></span></a><code>r</code>
</h4>
<p>Example input: <code>r</code></p>
<p>Attemps to reset the current set of touches by creating appropriate <code>u</code> 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 <code>touchstart</code> events for the same contact is very suspect and most likely means that you lost a <code>touchend</code> event somehow.</p>
<p>We try to discard obviously out-of-order events automatically, but sometimes it's not enough.</p>
<p>If the screen freezes you'll have to reboot the device. With careful use this will not happen.</p>
<h4>
<a id="d-contact-x-y-pressure" class="anchor" href="#d-contact-x-y-pressure" aria-hidden="true"><span class="octicon octicon-link"></span></a><code>d <contact> <x> <y> <pressure></code>
</h4>
<p>Example input: <code>d 0 10 10 50</code></p>
<p>Schedules a touch down on contact <code><contact></code> at <code><x>,<y></code> with <code><pressure></code> pressure for the next commit.</p>
<p>You cannot have more than one <code>d</code>, <code>m</code> or <code>u</code> <em>for the same <code><contact></code></em> in one commit.</p>
<h4>
<a id="m-contact-x-y-pressure" class="anchor" href="#m-contact-x-y-pressure" aria-hidden="true"><span class="octicon octicon-link"></span></a><code>m <contact> <x> <y> <pressure></code>
</h4>
<p>Example input: <code>m 0 10 10 50</code></p>
<p>Schedules a touch move on contact <code><contact></code> at <
D6B4
code><x>,<y></code> with <code><pressure></code> pressure for the next commit.</p>
<p>You cannot have more than one <code>d</code>, <code>m</code> or <code>u</code> <em>for the same <code><contact></code></em> in one commit.</p>
<h4>
<a id="u-contact" class="anchor" href="#u-contact" aria-hidden="true"><span class="octicon octicon-link"></span></a><code>u <contact></code>
</h4>
<p>Example input: <code>u 0</code></p>
<p>Schedules a touch up on contact <code><contact></code>. If you need the contact to move first, use a combination of <code>m</code> and <code>u</code> separated by a commit.</p>
<p>You cannot have more than one <code>d</code>, <code>m</code> or <code>u</code> <em>for the same <code><contact></code></em> in one commit.</p>
<h3>
<a id="examples" class="anchor" href="#examples" aria-hidden="true"><span class="octicon octicon-link"></span></a>Examples</h3>
<p>Tap on (10, 10) with 50 pressure using a single contact.</p>
<pre><code>d 0 10 10 50
c
u 0
c
</code></pre>
<p>Long tap on (10, 10) with 50 pressure using a single contact.</p>
<pre><code>d 0 10 10 50
c
<wait in your own code>
u 0
c
</code></pre>
<p>Tap on (10, 10) and (20, 20) simultaneously with 50 pressure using two contacts.</p>
<pre><code>d 0 10 10 50
d 1 20 20 50
c
u 0
u 1
c
</code></pre>
<p>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.</p>
<pre><code>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
</code></pre>
<p>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.</p>
<pre><code>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
</code></pre>
<p>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.</p>
<pre><code>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
</code></pre>
<p>The same pinch but with more chaotic (or natural) ordering.</p>
<pre><code>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
</code></pre>
<h2>
<a id="contributing" class="anchor" href="#contributing" aria-hidden="true"><span class="octicon octicon-link"></span></a>Contributing</h2>
<p>See <a href="CONTRIBUTING.md">CONTRIBUTING.md</a>.</p>
<h2>
<a id="license" class="anchor" href="#license" aria-hidden="true"><span class="octicon octicon-link"></span></a>License</h2>
<p>See <a href="LICENSE">LICENSE</a>.</p>
<p>Copyright © CyberAgent, Inc. All Rights Reserved.</p>
<footer class="site-footer">
<span class="site-footer-owner"><a href="https://github.com/openstf/minitouch">Minitouch</a> is maintained by <a href="https://github.com/openstf">openstf</a>.</span>
<span class="site-footer-credits">This page was generated by <a href="https://pages.github.com">GitHub Pages</a> using the <a href="https://github.com/jasonlong/cayman-theme">Cayman theme</a> by <a href="https://twitter.com/jasonlong">Jason Long</a>.</span>
</footer>
</section>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-64458786-1");
pageTracker._trackPageview();
} catch(err) {}
</script>
</body>
</html>