forked from williamfzc/pyminitouch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.py
84 lines (66 loc) · 2.27 KB
/
demo.py
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
import time
from pyminitouch import safe_connection, safe_device, MNTDevice, CommandBuilder
_DEVICE_ID = '3d33076e'
# ---
device = MNTDevice(_DEVICE_ID)
# It's also very important to note that the maximum X and Y coordinates may, but usually do not, match the display size.
# so you need to calculate position by yourself, and you can get maximum X and Y by this way:
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)])
# set the pressure, default == 100
device.tap([(400, 600)], pressure=50)
# long-time-tap
# for long-click, you should control time delay by yourself
# because minitouch return nothing when actions done
# we will never know the time when it finished
device.tap([(400, 600)], duration=1000)
time.sleep(1)
# swipe
device.swipe([(100, 100), (500, 500)])
# of course, with duration and pressure
device.swipe([(100, 100), (400, 400), (200, 400)], duration=500, pressure=50)
# extra functions ( their names start with 'ext_' )
device.ext_smooth_swipe([(100, 100), (400, 400), (200, 400)], duration=500, pressure=50, part=20)
# stop minitouch
# when it was stopped, minitouch can do nothing for device, including release.
device.stop()
# ---
# In another way, you needn't consider about device's life-cycle.
# context manager will handle it
with safe_device(_DEVICE_ID) as device:
# 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)
# ---
# What's more, you can also access low level API for further usage.
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)
# if you are using MNTDevice object, replace with this:
# builder.publish(device.connection)
# ---
# Of course, you may want to operate it just like using minitouch itself.
# send raw text to it
_OPERATION = '''
d 0 150 150 50\n
c\n
u 0\n
c\n
'''
with safe_connection(_DEVICE_ID) as conn:
conn.send(_OPERATION)