forked from electricbubble/gwda-ext-opencv
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gesture.go
44 lines (37 loc) · 974 Bytes
/
gesture.go
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
package uixt
import (
"image"
"sort"
"github.com/electricbubble/gwda"
)
func (dExt *DriverExt) GesturePassword(pathname string, password ...int) (err error) {
var rects []image.Rectangle
if rects, err = dExt.FindAllImageRect(pathname); err != nil {
return err
}
sort.Slice(rects, func(i, j int) bool {
if rects[i].Min.Y < rects[j].Min.Y {
return true
} else if rects[i].Min.Y == rects[j].Min.Y {
if rects[i].Min.X < rects[j].Min.X {
return true
}
}
return false
})
touchActions := gwda.NewTouchActions(len(password)*2 + 1)
for i := range password {
x, y, width, height := dExt.MappingToRectInUIKit(rects[password[i]])
x = x + width*0.5
y = y + height*0.5
if i == 0 {
touchActions.Press(gwda.NewTouchActionPress().WithXYFloat(x, y)).
Wait(0.2)
} else {
touchActions.MoveTo(gwda.NewTouchActionMoveTo().WithXYFloat(x, y)).
Wait(0.2)
}
}
touchActions.Release()
return dExt.PerformTouchActions(touchActions)
}