-
Notifications
You must be signed in to change notification settings - Fork 0
/
mouse.go
183 lines (149 loc) · 4.74 KB
/
mouse.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
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
package mouse
import (
"fmt"
"math"
"net/http"
"strconv"
"github.com/gin-gonic/gin"
"github.com/go-vgo/robotgo"
"github.com/topcoder520/rebotgoapi/util"
)
func init() {
robotgo.MouseSleep = 100
}
//MouseMoveLeft 鼠标左移
func MouseMoveLeft(ctx *gin.Context) {
strMove := ctx.DefaultQuery("move", "10") //移动距离
move, _ := strconv.ParseInt(strMove, 10, 64)
x, y := robotgo.GetMousePos()
robotgo.Move(x-int(move), y)
ctx.JSON(http.StatusOK, util.Success())
}
//MouseMoveRight 鼠标右移
func MouseMoveRight(ctx *gin.Context) {
strMove := ctx.DefaultQuery("move", "10") //移动距离
move, _ := strconv.ParseInt(strMove, 10, 64)
x, y := robotgo.GetMousePos()
robotgo.Move(x+int(move), y)
ctx.JSON(http.StatusOK, util.Success())
}
//MouseMoveUp 鼠标上移
func MouseMoveUp(ctx *gin.Context) {
strMove := ctx.DefaultQuery("move", "10") //移动距离
move, _ := strconv.ParseInt(strMove, 10, 64)
x, y := robotgo.GetMousePos()
robotgo.Move(x, y-int(move))
ctx.JSON(http.StatusOK, util.Success())
}
//MouseMoveDown 鼠标下移
func MouseMoveDown(ctx *gin.Context) {
strMove := ctx.DefaultQuery("move", "10") //移动距离
move, _ := strconv.ParseInt(strMove, 10, 64)
x, y := robotgo.GetMousePos()
robotgo.Move(x, y+int(move))
ctx.JSON(http.StatusOK, util.Success())
}
//MouseMove 移动鼠标
func MouseMove(ctx *gin.Context) {
strMove := ctx.DefaultQuery("move", "10") //移动距离
move, _ := strconv.ParseInt(strMove, 10, 64)
strangle := ctx.DefaultQuery("angle", "90") //移动角度
angle, _ := strconv.ParseInt(strangle, 10, 64)
angle = angle % 360
radian := math.Pi / float64(180) * float64(angle) //弧度
y1 := math.Sin(radian) * float64(move)
x1 := math.Cos(radian) * float64(move)
x, y := robotgo.GetMousePos()
robotgo.Move(x+int(x1), y+int(y1))
ctx.JSON(http.StatusOK, util.Success())
}
//MouseMove2 移动鼠标
func MouseMove2(ctx *gin.Context) {
strdistanceX := ctx.DefaultQuery("distanceX", "0") //X轴移动距离
distanceX, err := strconv.ParseFloat(strdistanceX, 64)
fmt.Println(err)
strdistanceY := ctx.DefaultQuery("distanceY", "0") //Y轴移动距离
distanceY, _ := strconv.ParseFloat(strdistanceY, 64)
x, y := robotgo.GetMousePos()
fmt.Println(x, y)
fmt.Println(distanceX, distanceY)
fmt.Println(x+int(distanceX), y+int(distanceY))
robotgo.Move(x+int(distanceX), y+int(distanceY))
ctx.JSON(http.StatusOK, util.Success())
}
//MouseLeftClick 鼠标左键单击
func MouseLeftClick(ctx *gin.Context) {
robotgo.Click()
ctx.JSON(http.StatusOK, util.Success())
}
//MouseLeftDoubleClick 鼠标左键双击
func MouseLeftDoubleClick(ctx *gin.Context) {
robotgo.Click("left", true)
ctx.JSON(http.StatusOK, util.Success())
}
//MouseRightClick 鼠标右键单击
func MouseRightClick(ctx *gin.Context) {
robotgo.Click("right")
ctx.JSON(http.StatusOK, util.Success())
}
/***********拖拽******************/
//MouseLeftToggle 鼠标左键下压
func MouseLeftToggle(ctx *gin.Context) {
robotgo.Toggle("left")
ctx.JSON(http.StatusOK, util.Success())
}
//MouseLeftToggleUp 鼠标左键下压解放
func MouseLeftToggleUp(ctx *gin.Context) {
robotgo.Toggle("left", "up")
ctx.JSON(http.StatusOK, util.Success())
}
//MouseRightoggle 鼠标右键下压
func MouseRightoggle(ctx *gin.Context) {
robotgo.Toggle("right")
ctx.JSON(http.StatusOK, util.Success())
}
//MouseRightoggleUp 鼠标右键下压解放
func MouseRightoggleUp(ctx *gin.Context) {
robotgo.Toggle("right", "up")
ctx.JSON(http.StatusOK, util.Success())
}
/**************************/
//MouseCenterClick 鼠标滚轮单击
func MouseCenterClick(ctx *gin.Context) {
robotgo.Click("center")
ctx.JSON(http.StatusOK, util.Success())
}
//MouseWheelDown 鼠标滚轮下压
func MouseWheelDown(ctx *gin.Context) {
robotgo.Click("wheelDown")
ctx.JSON(http.StatusOK, util.Success())
}
//MouseWheelUp 鼠标滚轮上还原
func MouseWheelUp(ctx *gin.Context) {
robotgo.Click("wheelUp")
ctx.JSON(http.StatusOK, util.Success())
}
//MouseWheelLeft 鼠标滚轮左
func MouseWheelLeft(ctx *gin.Context) {
robotgo.Click("wheelLeft")
ctx.JSON(http.StatusOK, util.Success())
}
//MouseWheelRight 鼠标滚轮右
func MouseWheelRight(ctx *gin.Context) {
robotgo.Click("wheelRight")
ctx.JSON(http.StatusOK, util.Success())
}
//MouseScrollMouseUp 鼠标滑轮向上滚动
func MouseScrollMouseUp(ctx *gin.Context) {
strMove := ctx.DefaultQuery("move", "10") //移动距离
move, _ := strconv.ParseInt(strMove, 10, 64)
robotgo.ScrollMouse(int(move), "up")
ctx.JSON(http.StatusOK, util.Success())
}
//MouseScrollMouseDown 鼠标滑轮向下滚动
func MouseScrollMouseDown(ctx *gin.Context) {
strMove := ctx.DefaultQuery("move", "10") //移动距离
move, _ := strconv.ParseInt(strMove, 10, 64)
robotgo.ScrollMouse(int(move), "down")
ctx.JSON(http.StatusOK, util.Success())
}