-
Notifications
You must be signed in to change notification settings - Fork 23
/
input
executable file
·137 lines (123 loc) · 2.13 KB
/
input
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
#!/bin/bash
CONFIG_FILE=".input.config"
KEY_X=53
KEY_Y=54
MIN_X=20
MAX_X=1004
MIN_Y=0
MAX_Y=960
declare INPUT
DOC=""
declare ORIENTATION
DOC+="
findInput <input type>
- Find event input by type
know types:
lm3530_led
proximity
sholes-keypad
qtouch-touchscreen
cpcap-key
accelerometer
compass
"
findInput() {
timeout 1 adb shell getevent > /tmp/inputs
cat /tmp/inputs | grep -B 1 "$1" | grep -Po "/dev/input/event(\d+)"
}
DOC+="
updateConfig
- Update config file, needed after device change
"
updateConfig() {
INPUT=$(findInput "touch")
echo "INPUT=$INPUT">$CONFIG_FILE
}
if [ -f $CONFIG_FILE ]; then
. $CONFIG_FILE
fi
if [ -z "$INPUT" ]; then
updateConfig
fi
DOC+="
tap <x> <y>
- send tap event on position
"
tap() {
touch $1 $2
execute
}
DOC+="
swipe <x1> <y1> <x2> <y2>
- send swipe event
"
swipe() {
touch $1 $2
touch $3 $4
execute
}
DOC+="
touch <x> <y>
- send touch event. This one keeps touch pressed.
"
touch() {
if [ -z "$ORIENTATION" ]; then
ORIENTATION=$(orientation)
fi
case $ORIENTATION in
0)
x=$(( $MIN_X + $1 ))
y=$(( $MIN_Y + $2 ))
;;
1)
x=$(( $MAX_X - $2 - 10 ))
y=$(( $1 - 20 ))
;;
2)
x=$(( $MAX_X - $1 ))
y=$(( $MAX_Y - $2 ))
;;
3)
x=$1
y=$(( $MAX_Y - $2 - 10 ))
;;
*)
x=$1
y=$2
;;
esac
sendevent $INPUT 3 $KEY_X $x
sendevent $INPUT 3 $KEY_Y $y
execute
}
# Send a command to execute event
# Also if no command was sent it will clean inputs
execute() {
sendevent $INPUT 0 2 0
sendevent $INPUT 0 0 0
}
# Send event to android device
sendevent() {
echo adb shell sendevent $@
adb shell sendevent $@
}
# get current orientation
orientation() {
# echo $(adb shell dumpsys input | grep 'SurfaceOrientation' | grep -oP "\d+")
echo $(./droid orientation)
}
help() {
cat <<TEXT
Send input to device, simulating input program inside android
usage: $0 <command>
$0 tap <x> <y>
$0 swipe <x1> <y1> <x2> <y2>
Other commands:
$DOC
TEXT
}
if [ "$(type -t $1)" == "function" ]; then
$@
else
help
fi